/*syslog_dema.c*/ /* 编写守护进程步骤: 1)创建子进程,父进程退出 2)在子进程中创建新会话 3)改变当前目录为根目录 4)重设文件权限掩码 5)关闭文件描述符 */ #include
#include
#include
#include
#include
#include
#include
#include
#define MAXFILE 65535 int main() { pid_t pc,sid; int i,fd,len; char *buf = "This is a Dameon /n"; len = strlen(buf); pc = fork(); if(pc<0) { printf("error fork /n"); exit(1); } else if(pc>0) exit(0); openlog("demo_update",LOG_PID,LOG_DAEMON); if((sid=setsid())<0) { syslog(LOG_ERR,"%s/n","setsid"); exit(1); } if((sid=chdir("/"))<0) { syslog(LOG_ERR,"%s/n","chdir"); exit(1); } umask(0); for(i=0;i
守护进程
最新推荐文章于 2023-03-22 22:51:04 发布