一 特征和编写规则
2. 调用setsid()创建一个新的对话期。
3. 设定其工作目录。(chdir())
4. 将文件创建屏蔽字设置为0 。(umask(0))
5. 关闭不再需要的文件描述符。(close(int))
二 例子
# include
# include
int
main(void)
{
int pid ;
int s_pid ;
file *fp ;
{
fprintf(stderr,"log file open error !\n") ;
exit(0) ;
}
if((pid =fork()) < 0)
return -1 ;
else
if( pid > 0 )
exit(0) ;
else
{
s_pid = setsid() ;
fprintf(fp,"setsid:= %d",s_pid) ;
umask(0) ;
chdir("/usr") ;
close(0) ;
close(1) ;
close(2) ;
sleep(100) ;
fclose(fp) ;
return 0 ;
}
}
精灵进程运行过程中的有关信息在/usr/log文件中。