Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: cleanup a cancelled CGI script

by cLive ;-) (Prior)
on Jun 08, 2004 at 21:15 UTC ( [id://362554]=note: print w/replies, xml ) Need Help??


in reply to cleanup a cancelled CGI script

I may be missing something, but is there anything wrong with fork?
#!/usr/bin/perl use strict; use warnings; use POSIX ":sys_wait_h"; $|++; print "Content-type:text/plain\n\nStarting script.....\n\n"; my $pid; if (!defined($pid = fork)) { die "Could not fork! $!"; } elsif ($pid) { # parent - clean up when child exits 1 while (waitpid($pid,WNOHANG) != -1); cleanup(); exit(0); } else { # child - does the processing print "Processing...\n\n"; sleep(5); print "Finished...\n\n"; exit(0); } sub cleanup { # do the clean up here }

In my test CGI $|++ doesn't seem to do anything. I can't work out why the output appears buffered - is that a fork side effect?

cLive ;-)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://362554]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (3)
As of 2024-04-20 01:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found