My single header C/C++ cross platform sub-process interaction library
subprocess.h was designed using
fork() on Linux/macOS. But a little birdie told me that I should be looking
posix_spawn() instead as it was faster.
TL;DR - I’ve switched the library to use POSIX spawn.
There are various reasons fork can be slow, so how does my library fare? This is running on my MacBook Air (M1, 2020):
|process created||fork()||posix_spawn()||% faster|
So it is faster, albeit not by a huge amount. Note this is a really synthetic example where my parent process doesn’t have a huge amount of state, but since using POSIX spawn is already faster I pulled the trigger and merged it.