Safe application spawning with fork+exec


/ Published in: C++
Save to your folder(s)

With the typical fork+exec method of spawning an application, you are left in the dark about failures in the exec. Once the fork occurs, the "main" process doesn't have any communication channel except waitpid, so it's hard to tell what happened.

With this function, a pipe is opened for the forked child to communicate errors. If the exec succeeds, then the pipe is automatically closed, and the main process reports success. Otherwise, the errno from exec is communicated through the pipe.

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.