【发布时间】:2017-04-15 13:33:29
【问题描述】:
假设我有 10 个子进程,它们在 exec 之前通过 setpgid(0,0) 移动到它们自己的进程组。 (每个孩子也有同样在他们自己的过程组中的孩子。) 我的前台进程获得 ctrl-c SIGINT 信号,我想将它传播到所有子进程(所有子进程都在不同的组中)。该怎么做?
希望快速草稿能更好地解释我的问题。
void handler(int signal) {
// resend SIGINT to all childs but childs are in different pgid
}
int main(int argc, char* argv[]){
struct sigaction sa;
sa.sa_handler = &handler;
sigaction(SIGINT, &sa, NULL);
pid_t pid[SIZE];
int i = 0;
// if argv is ge 2;
for (;i < SIZE; i++) // SIZE is number of the elements in argv
{
pid[i] = fork();
if(pid[i] == 0)
{
setpgid(0,0);
// execv self here but with one less element in argv;
}
}
while(1){}; // infinity loop (waits for ctrl-c from foreground process)
// prints to the terminal pid and pgid
// waits here for all childs to finish and then close self
}
【问题讨论】:
-
让每个父母给它的每个孩子发送一个
SIGINT?
标签: linux process signals sigint