Something like this:
if (fork() == 0)
Now, granted, I missed a bunch of error conditions around fork
, as well as omitting the Highlander Maneuver
, but that's the basic idea.
Note that you can reopen stdout and/or stderr and redirect them to a file, or you can pipe them into something that'll send you an email, whatever you want. If nothing else, you may want to reopen to /dev/null, just to sure you don't confuse subprocesses if you call any.