5 ms·
Linux Signals – Internals
- nul_byte 10y agoI keep meaning to learn Linux from the ground up, by following the bootloader assembly, kernel initialisation etc and be able to track it in the kernel code, but its so vast I forget half of it, as I try to make my way (sporadically) through all there is. There are so many hours in the day.
- Razengan 10y agoI get that feeling; I've been meaning to do that for OS X myself.
- seesomesense 10y agoAppendix A of Understanding the Linux Kernel (3rd edition) has a good overview of this. I am trying to read this book from cover to cover while I am in hospital. It is vastly more entertaining than the cable TV.
- jdub 10y agoOr you can read Linux Insides… :-) https://github.com/0xAX/linux-insides https://github.com/0xAX/linux-insides
- nemaar 10y agoI really hope when the time comes and someone reinvents the wheel and comes up with a new great OS, the new OS will NOT have signals. Those are one of the worst things ever invented. The idea that your code is randomly interrupted and it starts to execute something else is just mind-blowingly bad. The real fun comes when you want to use different libraries with different signal handling ideas in the same process. It all goes to very quickly. The worst thing is that no one had the courage to say "okay guys, this is bad, let's just forget it ever existed and create a better alternative". /rant
- smcl 10y agoI'm not an operating systems person, so I'm curious - what are the alternatives?
- Merad 10y agoWin32 uses messages for everything. While Windows does include signals[0], only three are actually used (SIGABRT, SIGFPE, SIGTERM), and in practice I don't think I've ever seen a Win32 program implement signal handlers. [0]: https://msdn.microsoft.com/en-us/library/xdkz3x12.aspx https://msdn.microsoft.com/en-us/library/xdkz3x12.aspx
- trungaczne 10y agoI don't think message queues and signals serve the same use case. Signal could be used for out-of-band communication.
- kevin_nisbet 10y agoYou may be right, but in practice the syscall is so limited that I think many programs basically process the syscall as a message anyways, that using a messaging model may make more sense, and be easier to work with. Someone correct me if I'm wrong, but because of the way the syscall callback operates, it could be interrupting threads at almost any stage. This makes executing the signal in a safe manner very difficult, and from the signal handler itself you can only run certain code. If i remember correctly, most signal handler implementations then get reduced to basically set some state and return, where the regular execution will then check for that state and react to it. Well, if your only going to process the signal during you main event loop anyways, then why not just exchange the information over a message queue, and send a message to the process when you want it to do something (ie reload configuration).
- trungaczne 10y agoWell, from what I know, sometimes you just have to have out of band communication, check the discussion in the comment here: http://250bpm.com/blog:70 http://250bpm.com/blog:70 It sounds like a necessary use case to me. While most people would probably not use it, that doesn't invalidate its existence. Most people would probably not touch any low level code either way.
- zAy0LfpBZLC8mAC 10y agoIt should be noted that the example code is defective: printf() is being called inside the while loop and in the signal handler, which could lead to the printf() in the loop being interrupted by the signal handler, which would call printf() again, but printf() is not reentrant.
- cyphar 10y agoI like the use of jprobes to show the call stack within the kernel. I wish all of the tracing functionality within Linux would have one API (like DTrace). I considered writing a module to provide such an API, but there's so many complications when trying to create conditional probes (you don't have enough power with eBPF, and the default string-based globbing is useless).
- FreeFull 10y agoDoesn't ctrl-z actually send SIGTSTP rather than SIGSTOP? I think the difference is that SIGTSTP can be caught, while SIGSTOP is always an unconditional stop.
- zvrba 10y agoThat's correct.
- brudgers 10y agoLots of good HN discussions of Linux signals: https://hn.algolia.com/?query=linux%20signals&sort=byPopularity&prefix&page=0&dateRange=all&type=story https://hn.algolia.com/?query=linux%20signals&sort=byPopular...