I need to send two signals to the process SIGUSR1 and SIGUSR2 in order to change a specific logical variable in the program ( SIGUSR1 sets true, SIGUSR2 sets false). So I wrote a signalHandler() function to control the behavior of SIGUSR1 or SIGUSR2 . The problem is this: how to set sigaction() to handle this particular task? I spent a lot of time on Google, I read everywhere that sigaction() should be used instead of signal() sigaction() . On the man page, I found this
int sigaction(int signum, const struct sigaction *act,struct sigaction *oldact);
in signum I need to set the type of signal that I want to process, then I have the sigaction parameter of the structure:
struct sigaction { void (*sa_handler)(int); void (*sa_sigaction)(int, siginfo_t *, void *); sigset_t sa_mask; int sa_flags; void (*sa_restorer)(void); };
in the first field, I thought I should set the name of my signal handler, but I do not know how to set other fields.
Finally, what is the use of: struct sigaction *oldact ?
source share