in reply to Child keeps parent from returning...?

Dear Bloodnok and Almut,

Thanks to your help.

The code that works after using setsid and closing the std* as suggested is the following returning immediately.
my $pid = fork; if ( defined $pid ) { unless ($pid) { # Detach from parent setsid or print("Can't detach from parent. Copy log and notify + cvs admin: $!"); close STDOUT; close STDERR; close STDIN; exec "perl ${script_dir}/auto_merge.pl $gUSER $lBranch"; die "Failed exec auto_merge.pl\nPlease copy log and notify cvs +admin\n\nExec failed: $!\n"; exit 1; } } .. .. exit 0;

Thanks a lot for your shared wisdom :)
live

Replies are listed 'Best First'.
Re^2: Child keeps parent from returning...?
by almut (Canon) on Apr 08, 2009 at 12:46 UTC

    There's only one problem left: if the close STDERR succeeds (which it usually does), but the exec fails, the die "..." (which outputs to STDERR) won't have anywhere to write...  In other words, you probably want to redirect STDERR instead of closing it, in order to take care of this case. Or save and restore the original STDERR before/after the exec (see open for how to do the latter).