|
又得麻烦大家了:
情况如标题所述
[PHP]#include <sys/types.h>
#include <stdio.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <syslog.h>
#include <errno.h>
#include <signal.h>
#include <sys/file.h>
/* initialize,sucess return 0,fail return 1 */
int
main(void)
{
pid_t pid;
int fd,fdsize;
signal(SIGTTOU, SIG_IGN);
signal(SIGTTIN, SIG_IGN);
signal(SIGHUP, SIG_IGN);
signal(SIGTSTP, SIG_IGN);
pid = fork();
if(pid < 0)
{
fprintf(stderr, "Error: Can't fork a child(first) process!\n");
return 1;
}
if (pid != 0)
exit (0);
if (setsid() < 0)
{
fprintf(stderr, "Error: setsid funciton fail!\n");
return 1;
}
pid = fork();
if (pid < 0)
{
fprintf(stderr, "Error: Can't fork a child(second) process!\n");
return 1;
}
if (pid != 0)
exit (0);
if (chdir("/") < 0)
{
fprintf(stderr, "Error: Can't change directory to \"/\"\n");
return 1;
}
for (fd = 0,fdsize = getdtablesize(); fd < fdsize; fd++)
{
if (close(fd) < 0)
{
fprintf(stderr, "Error: Can't close file describe %d.\n", fd);
return 1;
}
}
umask(0);
signal(SIGCHLD,SIG_IGN);
syslog(LOG_USER|LOG_INFO," rogram is beginning\n");
while (1)
{
system("date >>1.txt");
sleep (5);
}
exit (0);
}[/PHP]
我编译如下:
gcc -o watch watch.c
直接运行:#./watch
查看此进程
ps axj|grep watch
没有查看到此进程
其中./watch退出的状态用echo $?查看为0,是指父进程的退出状态吗?望解惑 |
|