http://www.perlmonks.org?node_id=683632


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