Hi guys,
I'm facing a new problem. Now I'm learning how to send signals to process in order to make them communicate. I was trying to create a process and when this process is created, send a signal to his father... But I had no success. I get a bunch of errors and warnings. Here's the code:
#include <stdio.h>
#include <unistd.h>
#include <signal.h>
#include <stdlib.h>
#include <sys/wait.h>
#define max 10
void handler(int signo);
void (*hand_pt)(int);
hand_pt = &handler;
int ppid, pid[max], i, j, k, n;
// So I created a pointer to a funcion (hand_pt)
// and this pointer is going to point to the funcion (handler)
void handler(int signo)
{
printf("It worked");
}
main(int argc, char **argv)
{
signal(SIGUSR1, hand_pt);
//this process will wait for the signal SIGUSR1
//and will be handled by hand_pt -> handler
pid[0]=fork();
if(pid[0]==0)
{
printf("Sending signal:\n\n");
ppid=getppid();
kill(ppid, SIGUSR1);
exit(0);
}
return(0);
}
Maybe I didn't understand how the signal function works... But as far as I know, to use a handler function I have to create a pointer to that function (in this case void (*hand_pt)(int); ) and assign to this pointer the address of the function that will handle the signal ( hand_pt = &handler; ). Is my line of tought correct ?
After that I'd be able to send a signal with the kill() fcn . What am I doing wrong ?
Thanks