Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^2: Killing process group run with IPC::Open3

by pm_sanchay (Initiate)
on Feb 03, 2012 at 05:52 UTC ( #951602=note: print w/ replies, xml ) Need Help??


in reply to Re: Killing process group run with IPC::Open3
in thread Killing process group run with IPC::Open3


Hi ikegami,

That's a good point and infact I tried exec first (that's why use of setpgrp).  But problem is I also need to capture <stdin> in my app. Here is example:

> cat app.pl
print "continue? "; $yesno=<STDIN>; print "--$yesno";

> perl fixed.pl 5 perl -e 'system("perl app.pl")'
continue? y
alarmed out
sent kill signal to 1
^C

> perl test.pl 5 perl -e 'system("perl app.pl")'
continue? y
--y
Child exit status: 0 signal: 0

Is there any way to map <STDIN> in fixed.pl ?


Comment on Re^2: Killing process group run with IPC::Open3
Re^3: Killing process group run with IPC::Open3
by ikegami (Pope) on Feb 03, 2012 at 07:06 UTC

    Capture an input? Your terminology makes no sense to me. What do you mean by "capture <stdin>"?

    Whatever it is you want to do, if you know how to do it with open3, keep doing it that way. There's nothing special about "fixed.pl" on that side of things.

    PS — Please don't use <pre>. At all. Place code, computer text, inputs, outputs, etc in <code></code> or <c></c> tags. And use <p> at the start of paragraphs.

Re^3: Killing process group run with IPC::Open3
by ikegami (Pope) on Feb 03, 2012 at 07:22 UTC

    So I ran a few tests. It seems that the child can't read from the parent's STDIN. I presume this is the problem to which you are referring.

    man 2 setpgrp explains

    At any time, one (and only one) of the process groups in the session can be the foreground process group for the terminal; the remaining process groups are in the background.

    I don't know what a session is, but adding setsid() appears to solve the problem.

      My bad for using pre. I will be more careful from now.

      Yes, I meant "child can't read from the parent's STDIN".

      setsid()

      does appear to work. But it has another issue - I don't understand what happens if a KILL signal is sent to parent (example cntl-c)? Will have to understand what setsid does.

      Thanks for your help.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://951602]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (10)
As of 2014-12-25 04:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (159 votes), past polls