i have a problem with SIGUSR1 and SIGUSR2
i coudnt understand it....could you help me with this problem:
Write a C program (give it the name: family.c) which receives no arguments. The program should fork exactly two children. One child should sleep for 2 seconds and then send the signal SIGUSR1 to his parent. The other child should sleep for 5 seconds and then send the signal SIGUSR2 to his parent. The parent, while busy counting from 0 to 9 –sleeping one second after each count- will ignore the first signal but handle the other signal with a signal handler that just prints the following: “Son! Stop making noise!”
this my solution but without using the signal
int main (void)
{
int child_pid;
int child_pid1;
int i;
/* define the signal handler for the CHLD signal */
/* and the child process forking code... */
child_pid = fork();
switch (child_pid) {
case -1: /* fork() failed */
perror("fork");
exit(1);
case 0: /* inside child process */
sleep(2); /* sleep a little, so we'll have */
/* time to see what is going on */
exit(0);
default: /* inside parent process */
break;
child_pid1 = fork();
switch (child_pid1) {
case -1: /* fork() failed */
perror("fork");
exit(1);
case 0: /* inside child process */
sleep(5); /* sleep a little, so we'll have */
/* time to see what is going on */
exit(0);
default: /* inside parent process */
break;
}
/* parent process goes on, minding its own business... */
/* for example, some output... */
for (i=0; i<10; i++) {
printf("%d\n", i);
sleep(1); /* sleep for a second, so we'll have time to see the mix */
}
return 0;
}