我有以下创建子叉的代码。我想在孩子在父母身上完成执行之前杀死它。怎么做?
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int i;
main (int ac, char **av)
{
int pid;
i = 1;
if ((pid = fork()) == 0) {
/* child */
while (1) {
printf ("I m child\n");
sleep (1);
}
}
else {
/* Error */
perror ("fork");
exit (1);
}
sleep (10)
// TODO here: how to add code to kill child??
}