Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Re: making fork() a flag, and wait()ing properly

by c (Hermit)
on Feb 08, 2002 at 19:09 UTC ( [id://144188]=note: print w/replies, xml ) Need Help??


in reply to Re: making fork() a flag, and wait()ing properly
in thread making fork() a flag, and wait()ing properly

Nice! Your last example of:

foreach my $node ( @devices ) { if( $do_fork ) { my $pid = fork(); if( !$pid ) { do_exciting_things(); exit 0; } } else { do_exciting_things(); } }

looks very much like my most recent rewrite after starting this thread, so i am very encouraged that I am actually starting to understand what it is you dudes actually are talking about :-)

maybe though you could clear up the fog for me on this:

use POSIX; my $do_fork = 1; $SIG{CHLD} = sub { while( ( my $pid = waitpid(-1, POSIX::WNOHANG()) ) > 0 ){ ... } }

this one has me scratching my head. if you'd rather point to a perldoc reference, i'm up for that as well. it looks as though you're defining a subroutine as a hash value, but i'm not certain where/how its being called.

thanks -c

Replies are listed 'Best First'.
Re: Re: Re: making fork() a flag, and wait()ing properly
by lestrrat (Deacon) on Feb 08, 2002 at 19:41 UTC

    Are you asking me about just the syntax? or about signal handling with %SIG ?

    As far as the syntax goes, my code is equivalent to something like this:

    my $coderef = sub{ .... }; ## now $coderef is a reference to a subroutine, ## which can be executed like this: ## ## $coderef->(); # $coderef->( @args ) ## $SIG{ CHLD }= $coderef;

    So that means you can actually create an anonymous subroutine, and assign it to a scalar. Which in turn can be assigned to a hash value :)

    As for the signal handling portion, perldoc perlipc will give you more information. Not sure what is the best resource for that... ( I could try to explain, but I'm not confident that my knowledge is 100% correct )

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2024-04-18 06:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found