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. 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)
. This will get the Process Group ID to the the same as the parent's 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))
.
An usual way of kill a process group is with killpg() system call. From man pages:
"killpg() sends the signal sig to the process group pgrp."
Along with killpg(), get/setpgid might be needed also to setup a group properly.
You can use this:
killpg( 0, SIGNALTYPE);
You can send signal to all childs.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.