You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Jan Eden <li...@janeden.org> on 2005/03/16 11:24:03 UTC

[users@httpd] CGI child processes

Hi,

I am trying to get a CGI script executed via Apache. The script should call another script and exit immediately, while the second script is still running in the background.

I already tried the Perl exec and fork functions, but Apache always seems to wait for the second script to finish before displaying the "Process has been started and will run in the background" message.

When I execute the CGI script from the command line, exec works as expected (i.e. the shell returns to the prompt immediately).

How can I get Apache to disregard the process started by the CGI?

Thanks,

Jan
-- 
There are two major products that come out of Berkeley: LSD and UNIX. We don't believe this to be a coincidence. - Jeremy S. Anderson

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] CGI child processes

Posted by Joshua Slive <js...@gmail.com>.
On Tue, 22 Mar 2005 10:04:03 +0100, Jan Eden <li...@janeden.org> wrote:
> Scott Gifford wrote on 16.03.2005:
> 
> >Jan Eden <li...@janeden.org> writes:
> >
> >> I am trying to get a CGI script executed via Apache. The script
> >>should call another script and exit immediately, while the second
> >>script is still running in the background.
> >
> >[...]
> >
> >> How can I get Apache to disregard the process started by the CGI?
> >
> >I believe you need to fork twice, so that the long-running process is
> >a child of init (not a child of Apache).  Something like (untested):
> >
> Hi Scott,
> 
> thanks for your hint. Unfortunately, double forking also does not help. Apache still waits for the long-running process to complete.

See:
http://www.webthing.com/tutorials/cgifaq.3.html#8

Joshua.

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] CGI child processes

Posted by Jan Eden <li...@janeden.org>.
Scott Gifford wrote on 16.03.2005:

>Jan Eden <li...@janeden.org> writes:
>
>> I am trying to get a CGI script executed via Apache. The script
>>should call another script and exit immediately, while the second
>>script is still running in the background.
>
>[...]
>
>> How can I get Apache to disregard the process started by the CGI?
>
>I believe you need to fork twice, so that the long-running process is
>a child of init (not a child of Apache).  Something like (untested):
>
Hi Scott,

thanks for your hint. Unfortunately, double forking also does not help. Apache still waits for the long-running process to complete.

Best,

Jan
-- 
There are 10 kinds of people:  those who understand binary, and those who don't

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] CGI child processes

Posted by Scott Gifford <sg...@suspectclass.com>.
Jan Eden <li...@janeden.org> writes:

> I am trying to get a CGI script executed via Apache. The script
>should call another script and exit immediately, while the second
>script is still running in the background.

[...]

> How can I get Apache to disregard the process started by the CGI?

I believe you need to fork twice, so that the long-running process is
a child of init (not a child of Apache).  Something like (untested):

  if (!defined(my $f1 = fork()))
  {
    die "fork failed: $!\n";
  }
  elsif ($f1)
  {
    # Parent
    exit(0);
  }
  elsif (!defined(my $f2 = fork()))
  {
    die "second fork failed: $!\n";
  }
  elsif ($f2)
  {
    # Child
    exit(0);
  }
  else
  {
    # Grandchild
    exec(...);
  }

----ScottG.

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org