I create process tree with fork() (about 3 child). I can easly send a signal to all of them by kill(-getpgrp(), signal_number), but how to do the same with sigqueue?
The sigqueue() function sends a signal to a process or a group of processes, they said, but unlike kill(), i can't use sigqueue() to send a signal to an entire process group by specifying a negative value in pid.
So how to do that ?
EDIT:
Code:
s1.c is a program where i "catch" the signals to take control over them. So the couple of s1 ( with the same group id) waits for signal from sigqueue().
int main (int argc,char *argv[])
{
int i=0;
char *do=argv[1];
int b=atoi(argv[2]);
int y=fork();
if(argc !=3)
{
printf("wrong arg number\n");
exit(0);
}
do{
switch(fork())
{
case -1:
perror("error \n");
exit(1);
break;
case 0:
execl("s1","s1.c",argv[1],argv[2], NULL);
break;
default:
sleep(2);
break;
}
i++;
}
while(i<3);
sleep(2);
printf("ssignal %d send to gpid : %d\n",b,getpgrp());
union sigval value;
value.sival_int = 0;
value.sival_ptr = 0;
if(sigqueue(getpgrp(), b, value) == 0) {
printf("signal sent successfully!!\n");
} else {
perror("SIGSENT-ERROR:");
}
return 0;
while(wait(0) != -1){}
return 0;
}
If your implementation does in fact support process group signaling in
sigqueue
, then you probably need to do exactly what you would do for the pid argument to kill:By the strict standard, however, you are out of luck.
sigqueue
supports neither the null signal (0) nor the ability to signal groups of processes: