LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-16-2012, 01:28 AM   #1
dvah
LQ Newbie
 
Registered: Jan 2012
Posts: 13

Rep: Reputation: Disabled
how to trigger a background tar archive process on apache server


I would like to trigger a background tar process on apache server by a client browser request for a page.
I tried to have a PHP script execute exec("tar.... command &", ...) on the server when it handle the page request from the client. The server trigger the tar command but instead of running it as a background process while it finish generating the page and return it to the browser, it wait untill the tar command is done.

How can I cause the server to run the tar in the backgound and return immediately to the user?
 
Old 09-16-2012, 11:47 AM   #2
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
This relates to the relationship of a web server and it's child CGI process. As the parent process, the web server launches the CGI child process with the child's stdout directed to a file descriptor on the web server that is open for reading. The web server wants to swallow all of the output from the child process, so it waits for the file descriptor to reach eof(), which normally doesn't happen until the child process terminates. This is all consistent with the behavior you are reporting.
In order for the web server to see eof() on it's child's output, you will need to coerce the child process to close it's stdout stream. For most applications, this is not possible, since the application simply isn't written with that scenario in mind. The solution, then, is probably to launch an intermediate CGI that can launch the tar process, but can also close it's standard output, so the web server can return a page to the client browser, and stop waiting for the child to complete.
--- rod.

Last edited by theNbomr; 09-16-2012 at 11:48 AM.
 
Old 09-16-2012, 08:27 PM   #3
dvah
LQ Newbie
 
Registered: Jan 2012
Posts: 13

Original Poster
Rep: Reputation: Disabled
theNbomr thanks,

questions:
1. if I close the child process stdout will it not trigger the server to close/kill the child process? or does the server allow the child process to continue running even after its stdout is closed? keep in mind that the archive process which is the function of this child process may take a long time.

2. In my case the child process is a PHP script, if I close the PHP stdout will it be good enough?
 
Old 09-17-2012, 11:00 AM   #4
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
I don't think there are any hard rules for this kind of thing. The specific web server will do whatever it sees fit. I think that an Apache web server will only look at the child process' standard output, and leave the child running. I'm not sure PHP is handled the same way as a CGI child, since PHP is, in some way, built into the web server, at east as I understand it. I've never really used PHP enough to know the behavior in this circumstance.
--- rod.
 
Old 09-18-2012, 10:22 AM   #5
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,453

Rep: Reputation: 447Reputation: 447Reputation: 447Reputation: 447Reputation: 447
PHP Code:
exec('nohup tar ... > /tmp/tar.output.txt 2> /tmp/tar.errors.txt < /dev/null &'); 
 
  


Reply

Tags
apache, process



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Error in TAR - tar: GNU features wanted on incompatible archive format. kuldeep.k Linux - General 3 08-14-2009 11:09 AM
tar this does not look like a tar archive exit depalyed from previous error tasay Linux - Software 1 07-01-2009 03:34 PM
Piping tar bzcat to add a file to a tar.bz2 archive DaveQB Linux - Software 0 06-02-2008 08:28 PM
how to run any binary in background - background process tej Linux - Newbie 1 08-16-2004 12:27 AM
Tar gives error when creating a tar file archive davidas Linux - Newbie 10 04-13-2004 12:35 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:52 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration