in reply to Re: Problems with flushing after fork()
in thread Problems with flushing after fork()

Thanks. Whilst this lets the desired output return immediately, this is all that happens - the sleep() is no longer executed. No process exists after the output comes back.

  • Comment on Re^2: Problems with flushing after fork()

Replies are listed 'Best First'.
Re^3: Problems with flushing after fork()
by ruzam (Curate) on Feb 12, 2010 at 05:57 UTC
    To complete the separation you must also dis-associate the forked child from the parent.
    use POSIX qw(setsid); ... # inside your forked child setsid() or die "Can't start a new session: $!";

      Thanks - I'll give that a try on Monday. Trying to have a couple of days sanity break now ;-)

Re^3: Problems with flushing after fork()
by ahmad (Hermit) on Feb 12, 2010 at 07:49 UTC

    Well, I've just tried it now and it works

    #!/usr/bin/perl use strict; use warnings; use CGI; my $q = CGI->new; print $q->header; if (my $pid = fork ) { print "Hello, world - PID $pid\n"; exit; }else{ close STDOUT; close STDERR; close STDIN; sleep(20); exit; }

    I have verified that the script is still running: ps auxx | grep perl

      Did you test this running as a CGI process or from the command line? It works fine for me from the command line but not when run as a CGI. Guess that Apache's adding complications.