473,396 Members | 2,111 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Using a Double-Fork in CGIC to Avoid Timeouts

I have a CGIC program that generates reporting output on-the-fly. At
times this generation can take a long time, and session timeouts occur
while users wait for the page results to be displayed.

To alleviate this problem, I would like to use fork(), so that a parent
process notifies the user that the report will be e-mailed, while a
detached child process generates and sends the report.

However, it appears that even without a "wait" command, my Apache web
server keeps the parent process alive until the child finishes running.
I'd like to know how to stop the parent process from waiting for the
child to finish. I've read quite a bit about using a "double-fork"
solution for this, but I've yet to find a clear example.

Here is a simplified version of the code as I currently have it:

pid_t pid, sid;

pid = fork();

/* Child Process */
if ( pid == 0 ) {
sid = setsid();

if ( sid < 0 )
exit(-1); /* Exit with failure */

/* Code for Report Generation Goes Here */

exit(0);

/* Parent Process: prints HTML notification with CGIC library */
} else if ( pid 0 ) {
cgiHeaderContentType("text/html");
fprintf(cgiOut, "<html><body>\n");
fprintf(cgiOut, "<p>The report will be e-mailed.</p>\n");
fprintf(cgiOut, "</body></html>\n");

fclose(cgiOut);
_exit(0);
}

Any help or resource suggestions would be greatly appreciated.

Thanks in advance,
Chad Vice
--
PLEASE NOTE: comp.infosystems.www.authoring.cgi is a
SELF-MODERATED newsgroup. aa.net and boutell.com are
NOT the originators of the articles and are NOT responsible
for their content.

HOW TO POST to comp.infosystems.www.authoring.cgi:
http://www.thinkspot.net/ciwac/howtopost.html

Aug 9 '06 #1
1 2318
ch*******@gmail.com wrote:
However, it appears that even without a "wait" command, my Apache web
server keeps the parent process alive until the child finishes running.
You need to close stdin, stdout, and stderr for the child.
Chris

--
PLEASE NOTE: comp.infosystems.www.authoring.cgi is a
SELF-MODERATED newsgroup. aa.net and boutell.com are
NOT the originators of the articles and are NOT responsible
for their content.

HOW TO POST to comp.infosystems.www.authoring.cgi:
http://www.thinkspot.net/ciwac/howtopost.html

Aug 9 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: S Manohar | last post by:
I need to pass a 'reference' to a double value to a function which changes that value. Each time the function is called, it needs to change different sets of values. In C I'd simply pass...
2
by: cupiemayo | last post by:
Hello. I'm trying to make a sort of generic integral class, holding the boundary values and the integrand. Eventually I'd like to use it inside a class, like the example below. I think the...
1
by: Randi | last post by:
Hi, Looking for some help with this payrool project I have for class. This is what the instructor asks for so far. I have it working without errors but am getting some funky numbers. I am not...
8
by: Jing Cheng | last post by:
Hi, I'm using ifstream reading data from a file, as following: ifstream finput("track.dat"); if(finput.fail()){ cerr << "Open input DATA file error!\n"; exit(-1);
27
by: MK | last post by:
I am a newbie. Please help. The following warning is issued by gcc-3.2.2 compiler (pc Linux): ================================================================== read_raw_data.c:51: warning:...
5
by: John Dumais | last post by:
Hello, I have been trying to figure out how to write an array of doubles (in this specific case) to a binary stream without using a loop. What I have been doing is... foreach(double d in...
6
by: semkaa | last post by:
Can you explain why using ref keyword for passing parameters works slower that passing parameters by values itself. I wrote 2 examples to test it: //using ref static void Main(string args) {...
1
by: Preben | last post by:
Hi, don't know if this is the correct group, but try anyway. I would like to use boostbindings from the boost sandbox together with my project where I use boost::numeric::ublas vectors and...
5
by: ASP.NET explorer | last post by:
The following piece of code (between comment /***************/ line )works fine. You can test is in console/win form/web page. Just print strResult. ...
3
by: mattyizzo | last post by:
Here is my code. Basically I'm trying to solve for CI and CF, where each use a bunch of constants and a variable or two which can have up to 10 values. I get the following error, however, at line...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.