sub RunCommand { my $pgm = shift; my @execargs = @_; $SIG{CHLD} = 'IGNORE'; # This should flush stdout. my $ofh = select(STDOUT);$| = 1;select $ofh; warn "Before first fork $$"; my $kpid = fork; defined($kpid) || die; if ($kpid) { # Parent process my $w = waitpid($kpid, 0); # warn "waitpid returned $w\n"; } else { close STDIN; close STDOUT; close STDERR; setsid() >= 0 or die; my $gpid = fork; defined($gpid) or die; if ($gpid) { my $w = waitpid($gpid, 0); # warn "waitpid returned $w\n"; } else { open(STDIN, "/dev/null") or die; open(STDERR, ">/dev/null") or die; # Child process exec($pgm, @execargs) or die; } CORE::exit(0); } } #### &RunCommand("/home/dbooth/rdf-pipeline/trunk/pid.perl"); #### #! /usr/bin/perl -w # Append the PID and date/time to /tmp/pid.txt # so that we can verify that this ran. use HTTP::Date; my $tmp = "/tmp/pid.txt"; open(my $fh, ">>$tmp") or die; my $t = time2str(time); print $fh "pid: $$ $t\n"; close $fh or die; exit 0;