Just messing around with signals and i have a question...
in my code i have kill(getppid(),SIGUSR2); 3 times but it only gets called once. Why and how can it get called more than once?
thanks
#include <iostream>
#include <signal.h>
#include <sys/types.h>
#include <signal.h>
using namespace std;
static int alarm_fired = 0;
void ding (int sig)
{
alarm_fired = 1;
}
void you (int sig)
{
cout<<"second signal"<<endl;
}
int main(int argc, char *argv[])
{
pid_t pid;
cout<<"Alarm Application"<<endl;
signal (SIGUSR1,ding);
signal (SIGUSR2, you);
pid = fork();
switch(pid) {
case -1:
cout<<"error"<<endl;
case 0:
sleep(5);
kill(getppid(),SIGUSR1);
kill(getppid(),SIGUSR2);
kill(getppid(),SIGUSR2);
kill(getppid(),SIGUSR2);
exit (0);
}
cout<<"waiting for alarm"<<endl;
pause();
if(alarm_fired) cout<<"ding"<<endl;
cout<<"done"<<endl;
return 0;
}