Case 2 : A large (16 MB) alternate signal stack

This time, we deliberately allocate a generous amount of space for the alternate signal stack—16 megabytes. It can now handle a few thousand continuous signals. But, of course, at some point it will also overflow:

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

In another Terminal window, run the shell script:

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

Now the output in the original window:

<...> s=1 ; total=1; stack 0x7fd7339239b0 s=2 ; total=2; stack 0x7fd7339232b0 s=3 ; total=3; stack 0x7fd733922bb0--snip-- s=2 ; total=9354; stack ...

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.