on what thread the signal_callback is called?
Depends on how you send the signal.
- If you send a signal using
raise
, then the callback will be called in the same thread.
- If you send a signal using
pthread_kill
, then the signal callback will be called in the thread that whose id was passed to pthread_kill
.
- If you send a signal using
kill
then I think it's best to quote documentation:
POSIX.1 requires that if a process sends a signal to itself, and
the sending thread does not have the signal blocked, and no other
thread has it unblocked or is waiting for it in sigwait(3), at
least one unblocked signal must be delivered to the sending
thread before the kill() returns.
There will be differences if
if I ... call exit in the signal_callback - will the application terminate gracefully?
No, exit
is not an async safe function. It's not OK to call it from a signal handler.
Regarding edit: _exit
is async safe so you may call it. But it won't call registered cleanup functions, nor would the stack be unwound, so I wouldn't describe it as "graceful" as such.
P.S. main
must return int
.