#!/usr/bin/perl use strict; use POSIX qw(:signal_h); $|++; my $pid = fork(); if ($pid) { my $sigset = POSIX::SigSet->new; my $blockset = POSIX::SigSet->new(SIGCHLD); $SIG{CHLD} = sub { print "$$: Reaping a child process in child signal handler ...\n" }; sigprocmask(SIG_BLOCK, $blockset, $sigset)); print "$$: Parent sleeping 5 seconds at [".localtime()."] ...\n"; sleep 5; print "$$: That was refreshing. The time is now [".localtime()."].\n"; sigprocmask(SIG_SETMASK, $sigset); exit(0); } else { print "$$: \tChild sleeping for 2 seconds ...\n"; sleep 2; print "$$: \tChild exiting at [".localtime()."] ...\n"; exit(0); }