linux 杀进程函数,如何杀死进程所有的子孙进程(Linux C)

编程入门 行业动态 更新时间:2024-10-11 21:24:37

linux 杀<a href=https://www.elefans.com/category/jswz/34/1771450.html style=进程函数,如何杀死进程所有的子孙进程(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)

本文发布于:2024-02-13 19:39:23,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1760468.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:进程   子孙   函数   linux   Linux

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!