4 ms·
> However, I guess if you fork() (which is not something you can do with the standard rust library AFAIK, so requires unsafe) https://github.com/rust-lang/rust
by cesarb 10y ago
> However, I guess if you fork() (which is not something you can do with the standard rust library AFAIK, so requires unsafe)
https://github.com/rust-lang/rust/blob/0c85f2a1bdb01666e74cd391df630da581f12ad0/src/libstd/sys/unix/process/process_unix.rs#L39 https://github.com/rust-lang/rust/blob/0c85f2a1bdb01666e74cd...
Command::spawn() calls fork(). And you can schedule things to run on the child with CommandExt::before_exec().
- roblabla 10y agobefore_exec is unstable AFAIK ? EDIT: To be stabilized in 1.15 coming in two days. Oh well, at least, it shouldn't be possible to invoke UB. Hopefully :D
- amluto 10y agoThat's an unfortunate implementation. posix_spawn() is much faster in large applications because it doesn't need to make all MAP_PRIVATE mappings read-only for CoW purposes. Rust could hand-roll it by calling clone() directly, but the code is a bit tricky.