Skip to content

Instantly share code, notes, and snippets.

Created August 15, 2012 16:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/eb0558b216a97f383c2a to your computer and use it in GitHub Desktop.
Save anonymous/eb0558b216a97f383c2a to your computer and use it in GitHub Desktop.
# * * *
# somewhere at startup
# * * *
$SIG{CHLD} = sub { while (waitpid(-1, WNOHANG) > 0) {} };
# * * *
# somewhere in the code
# * * *
use POSIX;
sub job {
my ($job) = @_;
unless (fork()) {
my $exit = 0;
unless (eval { $job->(); 1 })) {
$exit = 1;
}
POSIX::_exit($exit);
}
}
job(sub { say "hello world from child process (pid $$)" });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment