Can IPC (inter process communication) be performed by signal capture and signal enhancement?
I made two programs. In the first program, I processed signals, and in another program, I just raised the signal that I want to process in another program. I work fine for me, but I want to communicate between the two programs using signals, and also want to send some bytes of data with this boost signal. How can i do this?
I want to send messages with this signal. Can I do it? Is it possible?
And also, what are the disadvantages and advantages of IPC signaling mechanisms?
Below is the working code of my two programs. With this, I can just pick up the signals and catch the signals, but I want to transfer data from one program to another.
In the second program, I used the first program process identifier. How can I make it dynamic.?
first program:
#include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <signal.h> #include <string.h> static void hdl (int sig, siginfo_t *siginfo, void *context) { printf("sig no = %d \n", sig); if(sig == SIGINT) exit(0); printf ("Sending PID: %ld, UID: %ld\n", (long)siginfo->si_pid, (long)siginfo->si_uid); } int main (int argc, char *argv[]) { struct sigaction act; sigemptyset(&act.sa_mask); act.sa_sigaction = &hdl; act.sa_flags = SA_SIGINFO; if (sigaction(SIGUSR1, &act, NULL) < 0) { perror ("sigaction SIGUSR1"); return 1; } if (sigaction(SIGINT, &act, NULL) < 0) { perror ("sigaction SIGINT"); return 1; } while (1) { sleep(1); } return 0; }
second program
#include <stdio.h> #include <signal.h> void main(void) { while (1) { sleep(1); kill(11558, SIGUSR1); } }