Can a Parent NOT wait on a CHILD Process? HOW? 
Author Message
 Can a Parent NOT wait on a CHILD Process? HOW?

On UNIX you fork() and exec() and use pipe() to communicate between father
and son.



Quote:
>Hi ALL,

>I've been trying to get the perl code quoted below to send a query string
to a
>child process but I don't want the parent script process to wait on the
child
>process neither do I want the child to wait on the parent. The query string



Sun, 26 Aug 2001 03:00:00 GMT  
 Can a Parent NOT wait on a CHILD Process? HOW?

Quote:



>> On UNIX you fork() and exec() and use pipe() to communicate between father
>> and son.

>Thank you for your response. As you can see in my original message quoted
>below I used the pipe | so that the parent can communicate with the child
>process, but my question is what code can I add to my code below so that the
>parent does not have to wait on the child and also so that the child does not
>have to wait on the parent. In other words I want the child to be {*filter*}ager
>:-)

They don't have to wait as it is. Both parent and child execute concurrently.
If you mean you want the IO between them not to block, then you should
read up on using non-blocking IO. You can use select (which is good if you
are familiar with it), or you can use IO::Select if you want what some would
consider a easier to understand version.

It boils down to not trying to read or write unless the filehandle won't
block. More code on your part.

--
Sam

 "... the whole documentation is not unreasonably transportable in a
 student's briefcase." - John Lions describing UNIX 6th Edition
 "This has since been fixed in recent versions." - Kernighan & Pike



Sun, 26 Aug 2001 03:00:00 GMT  
 Can a Parent NOT wait on a CHILD Process? HOW?

Quote:

> On UNIX you fork() and exec() and use pipe() to communicate between father
> and son.



> >Hi ALL,

> >I've been trying to get the perl code quoted below to send a query string
> to a
> >child process but I don't want the parent script process to wait on the
> child
> >process neither do I want the child to wait on the parent. The query string

Hi,

have a look at Proc::Simple!
You'll find it on CPAN.

Andre
--
+============================+
| Andre Pinnel               |

+============================+



Mon, 27 Aug 2001 03:00:00 GMT  
 Can a Parent NOT wait on a CHILD Process? HOW?

global3> $add = "title=$title&url=$url&email=$email&section=$section";

global3> open(LPR,"|$subprog") || die "can't fork $subprog: $!\n";
global3> print LPR $add;

You know, this smells enough like a HTTP POST operation that I'll
first suggest you look at LWP, particularly "perldoc lwpcook".  No
point in reinventing the low-level code to do something like this
when it's trivial in LWP (from lwpcook):

         use HTTP::Request::Common qw(POST);
         use LWP::UserAgent;
         $ua = new LWP::UserAgent;

         my $req = POST 'http://www.perl.com/cgi-bin/BugGlimpse',
                       [ search => 'www', errors => 0 ];

         print $ua->request($req)->as_string;

But, if you're actually insisting that it's not an existing protocol
(even as web-ish as it looks :), you can fork like so:

        defined(my $pid = fork) or die "Cannot fork: $!";
        unless ($pid) { # child does...
                ... your code here ...
                exit 0;
        }

Your code goes in there. :)

print "Just another Perl hacker,"

--
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying

Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me



Mon, 27 Aug 2001 03:00:00 GMT  
 Can a Parent NOT wait on a CHILD Process? HOW?

info> Hi, I work with Agni who posted this info request.  I have tried
info> both your suggestions but I still have the same problem.
info> Actually I am familiar with HTTP::Request and LWP, want I really
info> need is for the child to be executed and the parent does not
info> wait on the child.  Let me expain more.

info> I am using a web based input form.  The parent takes in the info
info> does some checking and sends it to the child to do a long
info> process.  I want the parent to report a message back to the
info> browser (Your request is being processed) before the child
info> completes.  I hope you can provide a solution, thanks Vladimir.

Ahhh... what you want is something similar to what I've already
written for one of my Perl WebTechniques columns, archived online at
<URL:http://www.stonehenge.com/merlyn/WebTechniques/>.  In particular,
look at the one called "search in progress" from Dec 97.

print "Just another Perl hacker and web whacker,"

--
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying

Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me



Thu, 30 Aug 2001 03:00:00 GMT  
 
 [ 9 post ] 

 Relevant Pages 

1. Stop parent but not child process

2. Signals and parent/child/child processes

3. PERLFUNC: wait - wait for any child process to die

4. PERLFUNC: wait - wait for any child process to die

5. exit from child process kills parent process

6. Child processes don't clean up (defunct processes left) even though SIGCHLD does wait()

7. parent code halts browser display until child process finishes

8. Parent/Child Relation with Win32::Process

9. parent/child processes

10. Q: How to have child process change var's in parent

11. Win32::Process (Parent/Child Communication)

12. memory sharing between parent/child processes - Perl internals knowledge needed

 

 
Powered by phpBB® Forum Software