Learn more about Israeli war crimes in Gaza, funded by the USA, Germany, the UK and others.

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

Want to build a fantastic product using LLMs? I work at Granola where we're building the future IDE for knowledge work. Come and work with us! Read more or get in touch!

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