Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > popen, popen3, and leftover processes

Reply
Thread Tools

popen, popen3, and leftover processes

 
 
Hal Fulton
Guest
Posts: n/a
 
      04-28-2004
I'm getting processes left lying around when I do things
like

io = IO.popen("foo") # or...
inp, out, err = Open3.popen3("foobar")

I've tried such things as closing the io object, but to
no avail.

I see no way of retrieving the pid in either case.

What can I do?

Thanks,
Hal



 
Reply With Quote
 
 
 
 
Jason Wold
Guest
Posts: n/a
 
      04-28-2004
>io=IO.popen("sleep 1000")
=> #<IO:0x40140a8c>

>io.pid

=> 2676

>puts `ps auwx | grep sleep`

ital 2676 0.0 0.1 1900 472 pts/0 S 23:58 0:00 sleep 1000
ital 2677 0.0 0.3 2048 872 pts/0 S 23:59 0:00 sh -c
ps auwx | grep sleep
ital 2679 0.0 0.1 1500 432 pts/0 S 23:59 0:00 grep sleep
=> nil


On Wed, 28 Apr 2004 15:52:49 +0900, Hal Fulton <(E-Mail Removed)> wrote:
>
> I'm getting processes left lying around when I do things
> like
>
> io = IO.popen("foo") # or...
> inp, out, err = Open3.popen3("foobar")
>
> I've tried such things as closing the io object, but to
> no avail.
>
> I see no way of retrieving the pid in either case.
>
> What can I do?
>
> Thanks,
> Hal
>
>



 
Reply With Quote
 
 
 
 
Gregory Millam
Guest
Posts: n/a
 
      04-28-2004
Received: Wed, 28 Apr 2004 15:52:49 +0900
And lo, Hal wrote:

> I'm getting processes left lying around when I do things
> like
>
> io = IO.popen("foo") # or...
> inp, out, err = Open3.popen3("foobar")
>
> I've tried such things as closing the io object, but to
> no avail.
>
> I see no way of retrieving the pid in either case.


No need for a pid

Process.wait


 
Reply With Quote
 
Jason Wold
Guest
Posts: n/a
 
      04-28-2004
Ah, but I just noticed that popen3 doesn't save the pid info on any of
the IO objects it returns. bug or missing feature?

On Wed, 28 Apr 2004 00:00:31 -0700, Jason Wold <(E-Mail Removed)> wrote:
>
> >io=IO.popen("sleep 1000")

> => #<IO:0x40140a8c>
>
> >io.pid

> => 2676
>
> >puts `ps auwx | grep sleep`

> ital 2676 0.0 0.1 1900 472 pts/0 S 23:58 0:00 sleep 1000
> ital 2677 0.0 0.3 2048 872 pts/0 S 23:59 0:00 sh -c
> ps auwx | grep sleep
> ital 2679 0.0 0.1 1500 432 pts/0 S 23:59 0:00 grep sleep
> => nil
>
>
>
> On Wed, 28 Apr 2004 15:52:49 +0900, Hal Fulton <(E-Mail Removed)> wrote:
> >
> > I'm getting processes left lying around when I do things
> > like
> >
> > io = IO.popen("foo") # or...
> > inp, out, err = Open3.popen3("foobar")
> >
> > I've tried such things as closing the io object, but to
> > no avail.
> >
> > I see no way of retrieving the pid in either case.
> >
> > What can I do?
> >
> > Thanks,
> > Hal
> >
> >

>



 
Reply With Quote
 
Hal Fulton
Guest
Posts: n/a
 
      04-28-2004
Jason Wold wrote:

>>io.pid


Thank you. After 2 a.m., my reading skills decline.

Hal



 
Reply With Quote
 
Hal Fulton
Guest
Posts: n/a
 
      04-28-2004
Gregory Millam wrote:

> No need for a pid
>
> Process.wait


Hmm, but I don't want to wait for it. I want to make sure the process
dies. I think io.pid may be the way to go.

Hal






 
Reply With Quote
 
Hal Fulton
Guest
Posts: n/a
 
      04-28-2004
Jason Wold wrote:

> Ah, but I just noticed that popen3 doesn't save the pid info on any of
> the IO objects it returns. bug or missing feature?


Well, that would be problematic.

It does seem like a missing feature to me.

Hal



 
Reply With Quote
 
Hal Fulton
Guest
Posts: n/a
 
      04-28-2004
Jason Wold wrote:
> Ah, but I just noticed that popen3 doesn't save the pid info on any of
> the IO objects it returns. bug or missing feature?


As it turns out, adding this will fix it:

pi.each do |x|
class << x
attr_accessor id
end
x.pid = pid
end

A bit ugly, but I'll modify my private copy this way until
I see something better...


Hal



 
Reply With Quote
 
nobu.nokada@softhome.net
Guest
Posts: n/a
 
      04-28-2004
Hi,

At Wed, 28 Apr 2004 16:08:58 +0900,
Hal Fulton wrote in [ruby-talk:98616]:
> > No need for a pid
> >
> > Process.wait

>
> Hmm, but I don't want to wait for it. I want to make sure the process
> dies. I think io.pid may be the way to go.


You don't need to wait for IO.popen, popen'ed IO waits the
child process at close. However, popen3 spawns child and
grand-child process which the command is executed as, so you
cannot wait the real command. This restriction is to get rid
of leaving a zombie process.

--
Nobu Nakada


 
Reply With Quote
 
Gregory Millam
Guest
Posts: n/a
 
      04-28-2004
Received: Wed, 28 Apr 2004 16:43:35 +0900
And lo, http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:

> Hi,
>
> At Wed, 28 Apr 2004 16:08:58 +0900,
> Hal Fulton wrote in [ruby-talk:98616]:
> > > No need for a pid
> > >
> > > Process.wait

> >
> > Hmm, but I don't want to wait for it. I want to make sure the process
> > dies. I think io.pid may be the way to go.

>
> You don't need to wait for IO.popen, popen'ed IO waits the
> child process at close. However, popen3 spawns child and
> grand-child process which the command is executed as, so you
> cannot wait the real command. This restriction is to get rid
> of leaving a zombie process.


Hmm. .. right, I never knew that .

irb(main):001:0> f = IO.popen("fortune")
=> #<IO:0x402be42c>
irb(main):002:0> f.read
=> "Do not meddle in the affairs of wizards, for they become soggy and hard to\nlight.\n\nDo not throw cigarette butts in the urinal, for they are subtle and\nquick to anger.\n"

# ps aux with irb running shows fortune <defunct>

irb(main):003:0> f.close

# ps aux with irb still running shows no fortune.

Thanks, good to know.


 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: leftover pyc files Andrea Crotti Python 21 11-04-2011 11:15 PM
leftover pyc files Andrea Crotti Python 0 11-02-2011 02:03 PM
Controlling processes and what to "feed" other processes Marc Heiler Ruby 1 05-24-2009 05:37 PM
Leftover thriftiness from you film days? John Navas Digital Photography 69 01-24-2008 02:36 AM
WIn XP leftover fax seems to try dialing out Ike Milligan Computer Support 2 05-13-2004 09:53 PM



Advertisments