Within one course, I wrote an application that, when sending a SIGTERM signal to it, outputs to the output the number of sent SIGUSR1 and SIGUSR2 signals. I wrote a program that sends the signals from the main program to the pid
#include <stdio.h> #include <signal.h> #include <stdlib.h> int signal_cntr1 = 0; int signal_cntr2 = 0; void sig_handler1(int unused){ signal_cntr1++; } void sig_handler2(int unused){ signal_cntr2++; } void sig_handler3(int unused){ printf("%d %d\n",signal_cntr1, signal_cntr2); exit(0); } int main(){ signal(SIGUSR1, sig_handler1); signal(SIGUSR2, sig_handler2); signal(SIGTERM, sig_handler3); while(1); return 0; } test program code
#include <stdio.h> #include <sys/types.h> #include <signal.h> #include <stdlib.h> int main(int v, char **c){ int i; if(v != 2){ exit(EXIT_FAILURE); } for(i = 0; i < 253; i++){ kill(atoi(c[1]), SIGUSR1); usleep(5000); } for(i = 0; i < 124; i++){ kill(atoi(c[1]), SIGUSR2); usleep(5000); } kill(atoi(c[1]), SIGTERM); usleep(5000); return 0; } but the work is such
brainiac@brainiac-Latitude-7480:~/workspace/linux_fund$ ./solution & [3] 4542 [2] Done ./solution brainiac@brainiac-Latitude-7480:~/workspace/linux_fund$ ./a.out 4542 78 40 [3]- Done ./solution brainiac@brainiac-Latitude-7480:~/workspace/linux_fund$ although in the test application, 253 sigusr1 and 124 sigusr2 signals are sent, and the application shows 78 and 40, respectively. Where am I wrong?