Case 1 – very small (100 KB) alternate signal stack

We deliberately allocate a very small amount of space for the alternate signal stack—just 100 kilobytes. Needless to say, it overflows quickly and segfaults; our handler for SIGSEGV runs, printing out some stats:

$ ./altstack 100Alt signal stack size = 102400Running: signal SIGUSR1 flags: SA_NODEFER | SA_ONSTACK | SA_RESTARTProcess awaiting signals ...

In another Terminal window, run the shell script:

$ ./bombard_sig.sh $(pgrep altstack) 120Sending 120 instances of signal SIGUSR1 to process 12811 ...

Now, the output in the original window:

<...> s=1 ; total=1; stack 0xa20ff0 s=2 ; total=2; stack 0xa208f0 s=3 ; total=3; stack 0xa201f0--snip-- s=1 ; total=49; stack 0xa0bff0 s=2 ; total=50; ...

Get Hands-On System Programming with Linux now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.