Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Acessing object fields and methods from a signal handler?

by dokkeldepper (Friar)
on Nov 27, 2008 at 19:13 UTC ( [id://726467]=perlquestion: print w/replies, xml ) Need Help??

dokkeldepper has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks,

I write a module that is intended to wrap all the stuff for running a command into an OO-module. However, I cant't figure out how to write a signal handler that can access the modules methods and variables.

The code looks basically like this:

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; } }

Replies are listed 'Best First'.
Re: Acessing object fields and methods from a signal handler?
by BrowserUk (Patriarch) on Nov 27, 2008 at 19:22 UTC

      Without answering directy, I admit there is a concptual confusion about the design of the class. In other words, it does not what I intended it should do.

      Some meditation and prayers to St. Richard Stevens required to get some enlightment.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://726467]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2024-04-19 23:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found