I want to send a copy of some data to a signal handler function, take the simplified example:
signal(SIGUSR1, handler);
void handler(int sig){
//...
_exit(some_variable);
}
The goal is to stop the process and make it return some_variable
value to the parent without making it a global variable. Mind that some_variable
is local to the project that catches the signal, not the process that raises the signal.
I woud like to be able to both raise the signal in another process (kill) (not the parent btw) and to be able to do it from a console (kill) or using a script, and that's the main reason for using signal()
, as it's good for both.
I understand that there are other ways of doing this but would really like to know if this can be done using signal()
or a related method.
Other threads on the site suggest that this can't be done like this but they are quite old, perhaps some newer solution exists.