i am trying to send a user defined (SIGUSR1 or SIGUSR2) signal from parrent process to child process. After child process takes the signal, it waits for 5 seconds and sends another user defined signal to parrent process. When parrent process takes the signal, it writes a string to the screen. I cant figure it out how to do that. I am trying to do that on linux terminal. Here is my code:
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
void wait_function(int signal_1)
{
signal(SIGUSR1,wait_function);
if(signal_1==SIGUSR1)
{
sleep(5);
}
}
void writeSomethingOnScreen(int signal_2)
{
signal(SIGUSR2,createAndWrite);
if(signal_2==SIGUSR2)
{
printf("Hello Stackoverflow!");
}
}
main()
{
pid_t pid;
pid=fork();
if(pid==0)/*child*/
{
signal(SIGUSR1,wait_function);
pause();
kill(getppid(),SIGUSR2);
exit(254);
}
if(pid>0)/*parent*/
{
signal(SIGUSR2,writeSomethingOnScreen);
kill(pid,SIGUSR1);
}
}