I want my program to wait for a signal which will be SIGUSR1, but currently does not work.
The class that will catches the signal:
#include<signal.h>
#include<unistd.h>
int main(int argc, char *argv[]){
int pid;
pid=getpid();
printf("PID: %d\n", pid);
pause();
void my_handler(int signum)
{
if (signum == SIGUSR1)
{
printf("Received SIGUSR1!\n");
}
}
signal(SIGUSR1, my_handler);
}
Program that will give the signal:
#include<stdlib.h>
#include<signal.h>
#include<unistd.h>
#include<time.h>
int main(int argc, char *argv[]){
int i;
printf("Filename: %s, Receiver PID: %s\n", argv[1], argv[2]);
FILE *fp;
fp=fopen(argv[1], "w");
kill(atol(argv[1]),SIGUSR1);
}
You would first run the receiver like ./receiver 1
then after you find the PID(ex 3375) of the receiver you would run ./signaler 1 3375
Pause is the function i'm using to wait but it's not working, would sigwaitinfo or sigsuspend work?
argv[2]
would be the PID to pass tokill
, notargv[1]
.