3 ms·
Right, however even this is harder than it looks. For example, what happens if exec fails? How do you print an error? Answer: very carefully - certainly not wit
by ridiculous_fish 9y ago
Right, however even this is harder than it looks. For example, what happens if exec fails? How do you print an error? Answer: very carefully - certainly not with printf!
- cryptonector 9y agoYou can write() to fildes 2, but I'd not recommend it. Instead what I'd recommend is that you have a pipe() for passing an error message (one byte will do) back to the parent, and then _exit().
- FooBarWidget 9y agoEven this is harder than it should be. What if the exec succeeds? The pipe is never closed. If you mark the pipe as O_CLOEXEC and rely on the parent treating EOF as success: what if the child crashes prematurely before exec? E.g. killed by sysadmin, or by OOM killer. What if a write() to the pipe fails?