package MyPack; use strict; use warnings; use Posix ":sys_wait_h"; use constant STATUS_STOPPED=>'stopped'; use constant STATUS_RUNNING=>'running'; $SIG{CHLD}=\&reap_child; sub new{ my $class=shift; my $self= bless{ _pid=>undef , _status=>STATUS_STOPPED }, $class; return $self; } sub run{ my $self=shift; my $command=shift; croak "Process: no comand ist given \n" unless $command; my $child= fork(); die "Process: Forking error $? \n" unless defined $child; if($child>0){ $self->{_pid}=$child; $self->{_status}=STATUS_RUNNING; } else { exec($command); } } sub reap_child{ if (waitpid($self->{_pid},WNOHANG) > 0) { $self->{_status}=STATUS_STOPPED; $self->{_pid}=undef; } }