sometimes linux thread can not stop, do like this:
[cpp] view plaincopy
#include
#include
#include
int main()
{
pid_t pid;
char cmd[50];
if((pid=fork())==0){
printf("child process ---in ---->\n");
while(1)
{
printf("sleep 2s ..\n");
sleep(2);
}
printf("child process ---end ---->\n");
exit(0);
}else if(pid>0){
printf("father process ---in ---->\n");
printf("child process pid is %d\n",pid);
memset(cmd, 0 ,sizeof(cmd));
sprintf(cmd, "kill -9 %d", pid);
printf("%s\n",cmd);
system(cmd);
waitpid(pid,NULL,0);
printf("father process ---end ---->\n");
exit(0);
}
}
阅读(1155) | 评论(0) | 转发(0) |