0
假設我有10個子進程在exec之前通過setpgid(0,0)移動到它們自己的進程組。 (每個孩子也有孩子,這些孩子也在他們自己的進程組中。) 我的前臺進程獲取ctrl-c SIGINT信號,我想將它傳播到所有子進程(所有孩子都在不同的組中)。怎麼做?如何將C中的信號從父進程傳播到自己進程組中的子進程?
希望快速草稿能更好地解釋我的問題。
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? – alk