sub run { my ($self) = @_; my $PID = fork(); # fork returns undef if it fails (defined $PID) || die "Could not fork successfully"; # fork returns the Process ID of the new process it # has created to the parent process, and 0 to the # child process, so if we have a "true" value in $PID # then we are in the parent if ($PID) { # so we let the parent store the PID # of the process which is "_run"-ning $self->{PID} = $PID } else { # otherwise we are in the child, so we # should call _run $self->_run(); # we sure to call exit here so our child # process cleans up nicely exit(); } } # you can call stop from the parent # process to kill the child, you can adapt # this to send any number of signals to # the child depending upon your needs sub stop { my ($self) = @_; kill "INT", $self->{PID}; }