How are signals handled in Unix?

2019-10-05 07:59发布

问题:

My question is that how are signals handled in Unix. Are they handled by making new thread or there is something else? Also what is the flow of execution of programme when a signal comes?

What I mean by flow of execution is that, let's say I am in middle of a function X and call to another function Y comes. So the compiler goes pauses the execution of function X and goes to function Y. After finishing the function Y the compiler again continues the execution of programme X from where it was paused. Similarly I would like to know how programme executes when a signal comes.

I am using settimer in my programme to execute a function. But when I lower the interval value the function is called again and previous execution is cancelled, though I am not sure about it. The code is too messy and long so I have not posted it here.

Thanks for looking into it..!

回答1:

The operating system stops running the thread receiving the signal and runs the signal handler. When it returns the original thread restarts where it was.

If the signal handler is already running when another signal comes in, the action is configurable in the sigaction call.