linux下实现进程异常退出后自动重启

int forkprocess(void)
{
 printf("forkprocess   running......\r\n"); 
 pid_t pid = 0;
 int  status;
 
 while(1)
 {
  pid = fork();
  if(pid < 0)
  {
   printf("fork error............\r\n");
   exit(1);
  }
  if(pid == 0)
  {
   printf("this is child prodess return............\r\n");
   return 0;
  }
  printf("wait child prodess........\n");
  waitpid(pid, &status, 0);
  printf("child prodess end........\n");
 } 
 return 0;
}

你可能感兴趣的:(进程/线程,COM,linux)