Tuesday, August 11, 2009

coding tips

1. #define size(a) ((sizeof(a)/(*a) or ((sizeof(a)/((a)[0])
2. const volatile int *a: is fine
3. shared library
$ gcc -fpic -c shrobj.c
$ gcc -shared -o libshared.so shrobj.o
$ gcc hello.c libshared.so
$ ./a.out
Hello World
4. generate a stack dump
void dump_stack(void)
{
char s[160];

sprintf(s, "/bin/echo 'where\ndetach' | dbx -a %d", getpid());
system(s);

return;
}

5. fastest IPC: pipe, socket, shared mem, named pipe, message queue...
6. popen-pclose()
7. daemon
8. line buffer: disable: setbuf(), setvbuf(): setvbuf(stdout, NULL, _IONBF, 0);
9. close(012); then dup(01,2,)<---first empty entry.
10 unix programming links

http://www.cse.buffalo.edu/~milun/unix.programming.html

No comments:

Post a Comment