live2dream95
live2dream95

Reputation: 6057

Determining which signal interrupted my system call (Linux)

After my system call has returned because it was interrupted by a signal, is there a way to determine exactly which signal type (i.e. child process termination) caused the interruption?

Upvotes: 2

Views: 1341

Answers (2)

Nikolai Fetissov
Nikolai Fetissov

Reputation: 84159

There's a number of facilities in Linux to deal with signals:

  • waitpid(2) could be used to wait inline for SIGCHLD
  • sigaction(2) could be used to setup handler functions to react to specific signals, the SA_RESTART flag here affects whether certain system calls are interrupted or restarted
  • sigprocmask(2) could be used to block a number of signals
  • sigwait(3) could be used to wait for number of signals inline
  • Latest kernels support signalfd(2), which is convenient when one needs to combine signal handling and non-blocking IO.

Then there's the whole next level of complexity when we start talking about threads, though if you deal with signals explicitly you usually don't really care which signal interrupted the system call.

Upvotes: 3

jldupont
jldupont

Reputation: 96716

You need to set an handler. Have a look here.

Upvotes: 3

Related Questions