How do C signals interact with the stack?

We know how C functions work. The program maintains a call stack, which contains stack frames corresponding to nested function calls. Calling a function means pushing a new stack frame onto the stack, and returning from a function means popping its stack frame off the stack.

C signal handlers are functions, but the calling mechanism is clearly different. They don’t get called in a “normal” way, and they don’t get to “return” a value. So how do these functions work? And how do they interact with “normal” C functions?

The BSD manual for sigaction explains:

Normally, signal handlers execute on the current stack of the process. This may be changed, on a per-handler basis, so that signals are taken on a special signal stack.

So signal handlers do reuse the same stack, under normal conditions.

Tagged #c, #programming.

Similar posts

More by Jim

👋 I'm Jim, a full-stack product engineer. Want to build an amazing product and a profitable business? Read more about me or Get in touch!

This page copyright James Fisher 2017. Content is not associated with my employer. Found an error? Edit this page.