简体   繁体   English

如何从子进程向所有进程发送信号?

[英]How to send a signal to all process from child process?

I 'm trying to do a socket programming example with using fork() call, my problem is: When a child process finished a job, i want to kill all other process. 我正在尝试使用fork()调用来执行套接字编程示例,我的问题是:当子进程完成一个作业时,我想杀死所有其他进程。 I think if i send a singal to others ... Is this possible or is any one tell me a way ? 我想如果我向其他人发送信号......这可能还是有人告诉我一个方法?

At the start of the partent (before it forks its children), call setpgid(0,0) . 在partent开始时(在它分叉子节点之前),调用setpgid(0,0) This will get the Process Group ID to the the same as the parent's PID. 这将使进程组ID与父进程的PID相同。 This PGID will be inherited by each child and any of the processes can send a signal to all processes in the group by calling kill(signal, -getpgid(0)) . 此PGID将由每个子进程继承,并且任何进程都可以通过调用kill(signal, -getpgid(0))向组中的所有进程发送信号。

An usual way of kill a process group is with killpg() system call. 杀死进程组的常用方法是使用killpg()系统调用。 From man pages: 从手册页:

"killpg() sends the signal sig to the process group pgrp." “killpg()将信号sig发送到进程组pgrp。”

Along with killpg(), get/setpgid might be needed also to setup a group properly. 与killpg()一起,可能还需要get / setpgid来正确设置组。

You can use this: 你可以用这个:

killpg( 0, SIGNALTYPE);

You can send signal to all childs. 您可以向所有孩子发送信号。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM