1)僵尸进程 2)孤儿进程 3)守护进程
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/stat.h>
int main(int argc, const char *argv[])
{
pid_t cpid =fork();
if(cpid>0)
{
/* while(1)
{
// wait(NULL);
printf("parent:%d %d %d\n",getpid(),cpid,__LINE__);
sleep(1);
}
*/
}
if(cpid==0)
{
//创建新的会话
pid_t sid=setsid();
//修改运行目录
chdir("/tmp");
//重设文件权限掩码
umask(0);
//关闭所有的文件描述符
for(int i=0;i<1024;i++)
{
close(i);
}
while(1)
{
//守护进程的任务代码
sleep(1);
}
}
return 0;
}