如何才能终止一个已经PID子进程的执行
IT晓夏 2007-10-23 03:38:12 如下产生的cpid子进程,在其中执行runit ,runit是个无限循环执行的操作,如何才能在父进程中根据需要停止该子进程的执行,而不影响父进程?
cpid = fork();
if (cpid == 0)
{//this is a child thread
if (execv("./runit", argv) == -1) {
printf("errno: %d\n",errno);
ERR("execv error!");
return FAILURE;
}
exit(0);
}
else
if (cpid>0)
{//this is parent thread
printf("child PID is %d.\n",cpid);
wait(&status);
}
else
printf("Error run.\n");