Let's say i create via fork a child process from a father process and i pass an X value to child process using a pipe.At first the child is on pause and i start it using a SIGINT signal.What i want to do is pass the value X to the signal handler used in pipe.Also,the value of i will change during the running of father process and i will have to pass it multiple times so i don't think making it global would work.Code:
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/wait.h>
void handler() {
//i would like to print the value of i here.
}
int main() {
int fd[2], s;
pipe(fd);
pid_t c = fork();
if (c == 0) {
signal(SIGINT, handler);
pause();
read(fd[0], &s, sizeof(s));
//if use printf("%d",s) here s=2 correctly.
}
if (c > 0) {
int i = 2;
sleep(1); //i don't want the SIGINT signal to terminate the child process so i wait for it to reach pause
kill(c, SIGINT);
write(fd[1], &i, sizeof(i));
}
}
How could this be done?