user3599803 user3599803 -4 years ago 52
C Question

pause() signal handler


function blocks until a signal arrives.
Assuming the process got a signal and pause() returned, does the signal handler will be executed before the code that follows the
call, or the result is unexpected?


void sigusr1_handler()
// .. handler code

void main()
// .. bind handler to SIGUSR1

pause(); // wait for SIGUSR1
// some more code

Does "some more code" will always be executed after
has finished, or there is a race condition? If so, what is the solution?

I cannot think of anything besides busy-waiting, but then the pause won't be needed at all..

Answer Source

Citing from the man page for pause(2):

pause() returns only when a signal was caught and the signal-catching function returned. In this case, pause() returns -1, and errno is set to EINTR.

You can be sure that your signal handler runs before some more code.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download