Interesting Links [0x04]
This week’s links are all to do with signals. What are signals, and why are they doing in my JVM? Ok, that is a misnomer - firstly signal exists in all POSIX-like OSes, and secondly they affect all applications, the JVM included.
The difference is that the JVM will process signals on behalf of the
managed code, compared to a native-compiled language. Imagine if you have
dereferenced into a NULL pointer, or performed a divide-by-zero error: in
native code, the application crashes. In Java, the application could say,
“hey, you’ve got a NullPointerException
” or “man, I know you didn’t pass
Math in elementary school, but don’t fret, here’s an ArithmeticException
for you to play with”. In both cases, managed code allows the end-user to
survive events that normally segfaults a native application.
Signal handling can be a world of pain when you’re not careful with the code,
assumptions, limitations and invariants that come with them - and there are
plenty. Be very familiar with man 7 signals
,
and read the following links:
- All about Linux signals
Good basic introduction - Use reentrant functions for safe signal handling
Some guidance on what to be aware of when writing a signal handler - Signals
More in-depth breakdown of the usages of the APIs - glibc: signals
Nuts and bolts of the API calls for signals - pthread sigmask won’t work in signal handlers
A sample of what a misunderstanding of the API could lead you to
Bonus
- The Design and Implementation of the FreeBSD Operating System - 2nd Ed
It’s funny to quote a BSD book when the OS I work in is Linux-based. However this book is a good read on the design of how signals are queued and dispatched, with Section 4.7 giving the logical unpinnings of how signals are implemented from the OS’s perspective.