linux下C++根据pid关闭程序进程

#include
#include
#include
#include
main()
{
pid_t pid;
int status;
if(!(pid= fork())){
printf(“Hi I am child process!\n”);
sleep(10);
return;
}
else{
printf(“send signal to child process (%d) \n”,pid);
sleep(1);
kill(pid ,SIGABRT);    //给pid所指的进程发送SIGABRT(中止一个程序)信号
wait(&status);
if(WIFSIGNALED(status))
printf(“chile process receive signal %d\n”,WTERMSIG(status));
}
}


执行 send signal to child process(3170)
Hi I am child process!
child process receive signal 6

你可能感兴趣的:(linux,C++)