Предположим, у меня есть 10 дочерних процессов, которые перемещаются в свою группу процессов с помощью setpgid(0,0) непосредственно перед выполнением exec. (У каждого ребенка также есть дети, которые также находятся в своей группе процессов.) Мой процесс переднего плана получает сигнал SIGINT ctrl-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
каждому из своих детей? - person alk   schedule 15.04.2017