Re:Learn and use fork(), vfork(), wait() and exec() system c...
by matheusmoreira on Wednesday October 30, 2019 @04:10PM
(#21402013)
In general signal safety is lost because the C standard library maintains global and thread-local data. For example, the various I/O functions make use of global buffers. Using the read and write system calls directly is safe: when interrupted, they either report their progress or return EINTR.
Re:Learn and use fork(), vfork(), wait() and exec() system c...
by gpderetta on Wednesday October 30, 2019 @04:12PM
(#21402044)
> vfork is perfectly predictable as long as you follow the basic rule: only invoke async-signal-safe functions until you call exec.
Unsurprisingly, that's also true for plain fork in a multithreaded program.
it's meant for cases where you want to avoid a bit of the fork overhead or if you need to spawn a subprocess from an existing memory-heavy process without getting a KILL from the kernel if overcommit is disabled (as the fork COW doubles your claim on memory even if you don't actually trigger a copy)