Spawning a process without wait not possible?

Spawning a process without wait not possible?

Post by Thomas Schreib » Tue, 10 Sep 1996 04:00:00



I want to spawn a process in a CGI Script and return
immediately without waiting the child process to finish.
This does not seem to be possible. I only see the output
in the browser after the client has finished too.

Is this a special feature? How can it be circumvented?

HTTPD is Apache 1.0.1, Language is Perl:

    if($pid = fork) {       # parent
        print "Parent finished.<P>";
        exit;
    }
    elsif (defined $pid) {  # child
        exec "start_long_running_batch_job";
    }
    else {
        die "Can't fork: $!.\n";
    }

Thomas

____________________________________________________________
infodirekt - Thomas Schreiber         Tel:  +49 89/324796-50
Frankfurter Ring 193a                 Fax:  +49 89/324796-51

________________________ See you at http://www.infodirekt.de

 
 
 

Spawning a process without wait not possible?

Post by Kurt J Lan » Tue, 10 Sep 1996 04:00:00



>I want to spawn a process in a CGI Script and return
>immediately without waiting the child process to finish.
>This does not seem to be possible. I only see the output
>in the browser after the client has finished too.
>Is this a special feature? How can it be circumvented?
>HTTPD is Apache 1.0.1, Language is Perl:
>    if($pid = fork) {       # parent
>        print "Parent finished.<P>";
>        exit;
>    }
>    elsif (defined $pid) {  # child
>        exec "start_long_running_batch_job";
>    }
>    else {
>        die "Can't fork: $!.\n";
>    }

It may depend on the shell you are using. We use the Bourne
shell and have no trouble. If we close stdin and stdout,
then start a process in the background, then exit, the
server knows we are finished with the connection and that
there is no more data to send. Hope this helps.
--
--


 
 
 

Spawning a process without wait not possible?

Post by Thomas Schreib » Wed, 11 Sep 1996 04:00:00





> >I want to spawn a process in a CGI Script and return
> >immediately without waiting the child process to finish.
> >This does not seem to be possible. I only see the output
> >in the browser after the client has finished too.

> >Is this a special feature? How can it be circumvented?

> >HTTPD is Apache 1.0.1, Language is Perl:

> >    if($pid = fork) {       # parent
> >        print "Parent finished.<P>";
> >        exit;
> >    }
> >    elsif (defined $pid) {  # child
> >        exec "start_long_running_batch_job";
> >    }
> >    else {
> >        die "Can't fork: $!.\n";
> >    }

> It may depend on the shell you are using. We use the Bourne
> shell and have no trouble. If we close stdin and stdout,
> then start a process in the background, then exit, the
> server knows we are finished with the connection and that
> there is no more data to send. Hope this helps.
> --
> --


Thanks!

that leads me to the solution for Perl - rewrite the above
code like this:

    print "Parent will finish.";
    close STDOUT;
    if($pid = fork) {       # parent
        exit;
    }
    elsif (defined $pid) {  # child
        exec "start_long_running_batch_job";
    }
    else {
        die "Can't fork: $!.\n";
    }

Thomas

____________________________________________________________
infodirekt - Thomas Schreiber         Tel:  +49 89/324796-50
Frankfurter Ring 193a                 Fax:  +49 89/324796-51

________________________ See you at http://www.infodirekt.de

 
 
 

1. How to pclose() a process without a wait() ?

Hi netters,
        I got an interactive program where SQL code is send to the server
and the output from the Server is displayed on the STDOUT.

Now the problem is; User can also say
        select*from xyz || xbox

what it means is that the output from the server should be displayed in a
X program called xbox. What Iam doing is popen("xbox","w") and writing the
output to the pipe. xbox reads from its STDIN and builts a list of data; at EOF,
it displays in a box. Now the problem is in order to sense EOF, the parent
program should pclose() the pipe. This satisfies the xbox requirements but
pclose() waits for the xbox to finish by doing a wait(). The parent program
doesn't regain the control till the child program exits which is user dependent.

I need to do a pclose() to indicate EOF condition the child process and at the
same time I dont want pclose() to wait.

BTW, iam using SUNOS 4.1.3 on SS10.

Any suggestions ?
And many many thanks in advance.

cheers,

2. Sun Cluster 2.2, Solaris 2.6 and Oracle9 release2

3. fork,exec and wait and wait and wait and wait

4. Operating systems

5. 'Could not spawn child process' problem with Apache 1.26

6. access_log -- NOT registering images, how?

7. Apache 1.3.6 spawns runaway process, not content related

8. bootable Linux CDROM (?)

9. Apache problem: Not enough space: couldn't spawn child process

10. spawned processes and process interdependencies

11. Possible to test ability to to kill process without doing it?

12. Is it possible to get the informations of children processes without getproc subroutine?

13. Killing processes waiting on I/O (was Re: Daemon or not?)