Hacker News new | ask | show | jobs
by cyphar 3636 days ago
Signals are an incredibly brittle interface. Not only can you lose signals all the time (if a signal is sent to a process while it is handling another signal then you can lose that signal), but you lose a lot of semantic information because the model of signal is "random callback that you jump to and you lose your old stack state while in the signal" is incredibly lossy. There's a lot of other problems (signals not being queueable, as well as the fact that signals expose a bunch of kernel race conditions by design) but you get the gist.

Unix did a lot of things right, but signals was certainly not one of them. Sometimes the simple ideas aren't the best ones.

2 comments

> if a signal is sent to a process while it is handling another signal then you can lose that signal

> signals not being queueable

Are you sure? I'm not an expert on signal handling, but I believe these statements are not true in the case of signalfd(2), which allows you to read signals from a file descriptor and does not require a signal handler.

Signal sending cannot block, so you'd need to have an unlimited amount of memory in order to guarantee that all signals are delivered. Not to mention that some signals allow you to block a process in the middle of a syscall (resulting in the lovely restart_syscall and EINTR hacks).

Also, signalfd(2) has its own lovely host of problems (caused by the fact that a file descriptor and signals don't match in abstractions). On fork(), sendmsg() or exec() or any other interesting event, the file descriptor starts to lean towards breaking POSIX. In addition, because of signals' interactions with threads, you get some even odder interactions when you read from the fd in a multithreaded program (they share the file descriptor table but will read different data).

It is necessarily true because sending signals cannot block and queueing an unbounded number of signals would require unbounded amounts of memory.
> signals not being queueable

real-time signals are queueable.