尝试写一个简单的守护进程
/** @File daemon.c * * Build a daemon process for game * */#include#include #include #include "daemon.h"int create_daemon(){ pid_t pid; pid=fork(); switch(pid) { case -1: //fprintf(stderr, "fork child failed!\n"); exit(EXIT_FAILURE); break; case 0: //fprintf(stdout,"child is here!\n"); for(;;) { sleep(3); } break; default: //fprintf(stdout,"child pid is [%d]\n", pid); break; } return 0;}
创建线程
#include#include #include pthread_t create_thread( void* pFunc){ pthread_t tid; if(pthread_create(&tid, NULL, (void*)pFunc, NULL) == 0) { fprintf(stdout, "create thread success!\n"); }else { fprintf(stderr, "create thread failed!\n"); exit(EXIT_FAILURE); } return tid;}