Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Re: Re: Re: Closing parent CGI after fork()

by hambo (Novice)
on May 11, 2004 at 00:31 UTC ( [id://352264]=note: print w/replies, xml ) Need Help??


in reply to Re: Re: Re: Closing parent CGI after fork()
in thread Closing parent CGI after fork()

Thanks Edan.

Well, I have done the project now, but take this into consideration for the upgrade - which I am already thinking about. My solution was to open a tiny browser window, make it the same colour as the background of the web page, and leave it running "hidden". A real cludge I know, but I really needed to move on here.
Thanks for the advice anyway
Couple of questions though:
  1. How do I go about re-opening STD(IN|OUT|ERR)?
  2. If I close STDOUT, how do I get hold of my STDOUT from the perl script or more importantly the system call?

merlyn gave me a useful link to his long-running CGI process, but it did not work as I expected.
I rather expected that every couple of seconds it would return, and update the page.
Instead, it waited till the traceroute completed altogther before giving the results.
I wondered whether this had to do with running it under Apache 2 rather than 1.3?
Have you any comments on his long-running process?

Thanks for your help though
Cheers
Hambo

--
Open Source - Where everything is QED
Perl - where programming is FUN

Replies are listed 'Best First'.
Re: Re: Re: Re: Re: Closing parent CGI after fork()
by edan (Curate) on May 31, 2004 at 14:04 UTC

    How do I go about re-opening STD(IN|OUT|ERR)?

    This is what I did:

    # throw away STDIN and STDOUT open STDIN, '<', '/dev/null'; open STDOUT, '>', '/dev/null'; # save STDERR to deal with later my $err_file = "/tmp/err.$$"; open STDERR, '>', $err_file;

    If I close STDOUT, how do I get hold of my STDOUT from the perl script or more importantly the system call?

    Well, as you see, you're not really closing STDOUT you are reopening it to some other place. This will cause all output that would ordinarily go to your program's standard STDOUT to go to the file specified in the open call above. That includes any output generated by system calls and the like, since it's going to the same filehandle, only in a child process in that case (system simply performs a fork and exec under the hood). If you needed to get your hands on that output, you'd have to direct it to a real file instead of /dev/null, as in the STDERR example above.

    HTH

    --
    edan

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (4)
As of 2024-04-16 19:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found