After abandoning my first attempt at learning Rust I'm now ready to give Rust 2018 a new try. With Rust being advertised as a system-level language I would like to investigate whether it's possible to implement a traditional, single-threaded Unix/POSIX shell in Rust at this point.
In C, such shells are implemented (among others) using a
SIGCHLD handler that reaps exiting background processes when the shell sits at the prompt and waits for user input.
Is my understanding that it's generally impossible to write general signal handlers in Rust correct? I took a look at the signal-hook crate which appears to be painstakingly coded to avoid any interaction with the Rust runtime (such as alloc) in its signal handlers. Instead, these signal handlers either set atomics, or perhaps do a single call to an async-signal-safe function such as
send(2) that communicates via an IPC mechanism with some receiving threads in the same process.
Unless either multiple threads or a multiplexing facility such as
select(2) or equivalent are used, there appears to be no way to react to signals while the main thread is blocked waiting for user input. Is this assessment correct?
If so, what is the idiomatic way in Rust to perform necessary signal handling, ideally in the context of a single-threaded application?