日期:2014-05-16 浏览次数:20779 次
#include ......
pid_t cpid;
void sigHandle(int sig)
{
printf("\nin sigHandle\n");
pid_t pid;
pid= waitpid(-1,NULL,0);
if (pid>0)
printf("pid=[%d] terminated\n",pid);
else
printf("waitpid error [%s]\n",strerror(errno));
return ;
}
int main()
{
char path[]="/home/test";
char pro_name[]="test";
pid_t pid;
signal(SIGCHLD,sigHandle);
pid=fork();
if(pid==0)
{cpid=getpid();
printf("cpid=[%d]\n",cpid);
if( 0 > execl(path,pro_name,par,"start",NULL))
// if( 0 > system(path))
{
printf("call program: [%s] failed!\n",pro_name);
}// sleep(1); //此处加上后SIGCHLD信号处理函数怎么不执行了呢??
printf("\nnever run here \n");
}
return 0;
}