I
I
Ivan2019-08-26 14:07:14
C++ / C#
Ivan, 2019-08-26 14:07:14

How to install custom SIGUSR1 and SIGUSR2 signal handler?

By default, the user signals SIGUSR1 and SIGUSR2 terminate a process or thread. How to make it so that they install their own handler? I tried to read various articles on this topic, but since I'm new to this topic, I couldn't transfer it for my needs.
And the need for the following is a number of producer threads (pthread) that execute a number of instructions in a cycle and at the end of each iteration wait for a SIGURS1 signal (sigwait) from the main consumer thread, and only after receiving the signal go to the next iteration. But due to default termination, they are therefore terminated.
Those. all that is needed here is the very fact of receiving these signals to move on to the next iteration, and they complete the process.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Dubrovin, 2019-08-26
@Steindvart

man signal

#include <signal.h>
void sigprocess (int sign){
 /* process signal here */
}

...
int main(){
...
 signal (SIGUSR1, sigprocess);
...
}

PS if the handler is not needed, you can
signal(SIGUSR1, SIG_IGN);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question