Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re: Fork and exec

by mr_mischief (Monsignor)
on Apr 30, 2008 at 06:16 UTC ( #683632=note: print w/replies, xml ) Need Help??

in reply to Fork and exec

You can set $SIG{CHLD} to 'IGNORE' if you don't want to wait for status of your children. There are other ways, too, but that's the easy way. See perlipc and waitpid for more info.

The exit is there to make sure your child exits cleanly in case the exec() fails. You don't want each child going back and forking ten times because they can't exec the proper process for whatever reason, right? If that exec fails and you don't exit, you've unleashed a forkbomb on your machine. Your sysadmin might not be happy. See exec for more info.

BTW, your declaration of $a is missing a sigil, a for loop is more idiomatic when using a fixed count, and you're missing two important lines at the top:

use strict; use warnings; $SIG{CHLD} = 'IGNORE'; # my $a; # no longer necessary -- was a loop var where the loop # number range idiom will suffice for ( 1..10 ) { unless ( fork() ) { # Here I want execute and continue without # wait the status exec( 'echo', 'foo!' ); exit( 0 ); } }

Replies are listed 'Best First'.
Re^2: Fork and exec
by MidLifeXis (Monsignor) on Apr 30, 2008 at 17:16 UTC
    Your sysadmin might not be happy.

    That is putting it mildly :). I remember calling a professor as his machine started to alarm due to a self-inflicted (read: prof did it to self) fork bomb. Getting onto the machine and rebooting without losing data was, umm, fun.

    Thankfully, the prof happened to be one of the reasonable ones, and it was "his" machine, so other than the two of us, there was not a lot of impact :)


Re^2: Fork and exec
by perlmonkdr (Beadle) on Apr 30, 2008 at 23:10 UTC

    Thk 4 your reply

    I'm afraid not work, if i do something like this exec "perl -e sleep(20)"; the parent process wait for finish all childs, one little thing, i tested it on win, remember that in this OS Perl emulate fork, it works fine 4 U on *nix?

    Thk a lot

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2018-11-13 22:01 GMT
Find Nodes?
    Voting Booth?
    My code is most likely broken because:

    Results (159 votes). Check out past polls.