in reply to PERL CGI - waiting page is hanging
I have cracked this. The clue is here. Although it is referring to something slightly different, the principal is the same: because the child created in the fork inherits the STDIN and STDOUT connected to the web browser, the web browser connection is held open. The parent is exiting properly, and the child is taking over its role, making it seem to the user like nothing has changed. To solve this, you can reopen STDIN and STDOUT to another destination (in my case /dev/null). Obviously you will need to be sure that you are done outputting things to the web browser. The code above is now:
which works as you'd want it to. In conjunction with some AJAX you finally get the task maangement you want.#!/usr/bin/perl -wT use strict; use CGI ':standard'; die "Could not fork()\n" unless defined (my $kidpid = fork); if ($kidpid) { print header; print "done\n"; print STDERR "Parent exited\n"; exit; } else { open STDOUT, '>/dev/null' or die "Can't open /dev/null: $!"; open STDIN, '</dev/null' or die "Can't open /dev/null: $!"; sleep 20; print STDERR "Child exited \n"; }
If you want to have a go at storing and restoring STDOUT for later, you can try some examples here.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: PERL CGI - waiting page is hanging
by Anonymous Monk on Jan 03, 2010 at 21:12 UTC | |
|
Re^2: PERL CGI - waiting page is hanging
by Anonymous Monk on Feb 11, 2012 at 07:42 UTC | |
by Anonymous Monk on Apr 29, 2012 at 20:17 UTC |