进程函数,如何杀死进程所有的子孙进程(Linux C)"/>
linux 杀进程函数,如何杀死进程所有的子孙进程(Linux C)
杀死进程的子进程利用kill(ChildPid, SIGTERM)就可以做到,但是如何杀死子进程的儿子喃,这里要用到一个进程组的概念,kill函数可以利用传递负pid的方法将SIGTERM信号传送给具有相同进程组号的所有进程。
如下是man对kill函数的一个的一个描述
#include
#include
/*
pid>0:signal sig is sent to pid
pid==0:sig is sent to every process in the process group of the current process
pid==-1: sig is sent to every process for which the calling process has permission to send signals, except for process 1 (init)
pid
*/
int kill(pid_t pid, int sig);
测试程序:在Redhat下运行,通过ps的方式来观察子孙进程的创建和销毁
#include
#include
#include
#include
#include
#include
#include
int main(void)
{
pid_t pid;
int stat;
for (;;)
{
pid = fork();
if (pid == 0)
{
/
更多推荐
linux 杀进程函数,如何杀死进程所有的子孙进程(Linux C)
发布评论