วันศุกร์ที่ 21 มีนาคม พ.ศ. 2551

How to create folder yy/mm/dd by using shell script

If you don't have time to create a lof of directory for keep log file by yy/mm/dd.
you can use a simple shell script for create it automatically as follow.


#!/bin/bash

numdays=( 0 31 29 31 30 31 30 31 31 30 31 30 31 )
year=${1:-2008}
month_begin=${2:-1}

month_end=${2:-12}
seq $month_begin $month_end while read month ; do

seq 1 ${numdays[$month]} while read day ; do

mkdir -p $( printf "%04d%02d%02d" $year $month $day )

done
done

Make it simple :)

วันพฤหัสบดีที่ 20 มีนาคม พ.ศ. 2551

How to write data to device with non cache (DIRECT I/O).

Last year (2007) when I worked at my 1st comapany. I was assigned to write interface program for read/write to ATA device with non cache memory.

On Linux u can use basic function as read/write for do it. Not like window that u must use writeasync/sync.

But a little tricky is a first step to open device with direct IO mode. you just add flag O_DIRECT and it will work correctly with non cache access.

example;
fd = open(devName, O_RDWR |O_DIRECT|O_RSYNC | O_SYNC );

:)
Cheers.

็How to create linux shared library (.so)

Hi guys... this is my first topic.
I would like to talk about the way to create shared library on Linux.

Last week I was assigned to create dll version on Linux . That is shared library.
Don't talk anymore ... let see the way :) .

This work will build new library that use a OCCI library internal.

1.Declare nessecary macro.
CC = g++

OBJ = Th_lexer_lib2_linux.o Worddict.o
OCCI_SHARELIBS = /home/nat/oracle/product/10.2.0/db_1/lib/
OCCI_HEADER = /home/nat/oracle/product/10.2.0/db_1/rdbms/public/

all:Th_lexer_lib2_linux.so
@echo "Build TestBox_linux module complete!!"
clean:
rm -fr *.o Th_lexer_lib2_linux.so
@echo "Remove all TestBox_linux modules!!!"


2.Build nessacary object files that use in library. flag "-fpic" is need.

Worddict.o:Worddict.cpp Thaifunc.h Thaihead.h TypeLinux.h
$(CC) -fpic -c Worddict.cpp

Th_lexer_lib2_linux.o:Th_lexer_lib2_linux.cpp TypeLinux.h
$(CC) -I $(OCCI_HEADER) -fpic -c Th_lexer_lib2_linux.cpp


3.After we get all object files we will collect them to new library by using -shared.
Th_lexer_lib2_linux.so: Th_lexer_lib2_linux.o Worddict.o
$(CC) -shared -o Th_lexer_lib2_linux.so Worddict.o Th_lexer_lib2_linux.o -L. -locci -lclntsh

That's all .... now you can get new library that all function can access by not using _declspec(dllexport) in c code like as window dll.

If you want to limited scope for access you must include mapfile for define local and global part of library.

In g++ complier you must use extern keywords for defined function name correctly for protect undefined symbol problem when you call that function.

extern "C"{
void function_a();
}

And you can check all modules in library by using
nm "library_name"

Goodluck ,