Category Archives: Linux

Linux shared memory & semaphore

Show all info:                      ipcs delete specific item:           ipcrm [-m|-s]

Posted in Linux | Leave a comment

Linux daemon program

#include <unistd.h> #include <signal.h> #include <sys/param.h> #include <sys/types.h> #include <sys/stat.h> void init_daemon(void) { int pid; int i; if(pid=fork()) exit(0);//是父进程,结束父进程 else if(pid< 0) exit(1);//fork失败,退出 //是第一子进程,后台继续执行 setsid();//第一子进程成为新的会话组长和进程组长 //并与控制终端分离 if(pid=fork()) exit(0);//是第一子进程,结束第一子进程 else if(pid< 0) exit(1);//fork失败,退出 //是第二子进程,继续 //第二子进程不再是会话组长 for(i=0;i< NOFILE;++i)//关闭打开的文件描述符 close(i); chdir(“/tmp”);//改变工作目录到/tmp umask(0);//重设文件创建掩模 return; … Continue reading

Posted in Linux | Leave a comment

Linux 线程

1. 在Linux上获得线程id #define gettid() syscall(__NR_gettid) 用到的地方 gettid() 2. 查找进程ID ps -ef | grep 进程name 3. 显示特定进程的线程 ls  /proc/进程ID/task 4. 当用pthread_creat创建线程时, 当线程函数执行完,线程会自行消亡  (Uncertain) 5. 编译 多线程 程序 gcc -g -o test test.c -lpthread              test 是文件名

Posted in Linux | Leave a comment