Reputation: 150
I am writing a program that needs to catch the ctrl-c event. And I learned that I can call signal
function or sigaction
function in signal.h
to customize what to do when the process receives a SIGINT signal. But I am also curious what is the mechanism for such a signal listener. In other words, how can a process keep waiting for a specific signal while continuing to execute its code?
Upvotes: 0
Views: 154
Reputation: 780899
The process doesn't "wait" for the signal. Calling sigaction()
tells the operating system to force the process to take the specified action when the process receives the specified signal. When this happens, the process is interrupted and forced to call the registered handler.
Upvotes: 3