Forum: Ruby How to get list of all processes and the kill by name

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
18607dc7098d879b13f5ed22a70c4302?d=identicon&s=25 Eric Milford (ericindc)
on 2009-03-31 05:49
I am working on a scraper that blows up if an instance of Firefox is
already running (launched via Firewatir) so I want to put in code that
first checks for any existing Firefox processes and issues a kill to
their PIDs.

I'm really new to Ruby -- how can I best accomplish this?  Thanks.
9d4960f8319664f0f7896230eebace73?d=identicon&s=25 Glen Holcomb (Guest)
on 2009-03-31 16:14
(Received via mailing list)
I would just use the system for it.  But if you really want to do it in
Ruby
you could do something like this:

process_list = `ps aux | grep firefox`.split("\n")
process_list.each do |process|
  process = process.split(' ')
  command ||= []
  command << process.last
  pid ||= []
  pid << process[1]
end

Then you can kill stuff based on command to your hearts content.


On Mon, Mar 30, 2009 at 9:49 PM, Eric Milford <ericmilford@gmail.com>
wrote:

> I am working on a scraper that blows up if an instance of Firefox is
> already running (launched via Firewatir) so I want to put in code that
> first checks for any existing Firefox processes and issues a kill to
> their PIDs.
>
> I'm really new to Ruby -- how can I best accomplish this?  Thanks.
> --
> Posted via http://www.ruby-forum.com/.
>
>


--
"Hey brother Christian with your high and mighty errand, Your actions
speak
so loud, I can’t hear a word you’re saying."

-Greg Graffin (Bad Religion)
Aee77dba395ece0a04c688b05b07cd63?d=identicon&s=25 Daniel Berger (djberg96)
on 2009-03-31 16:45
(Received via mailing list)
On Mar 30, 9:49 pm, Eric Milford <ericmilf...@gmail.com> wrote:
> I am working on a scraper that blows up if an instance of Firefox is
> already running (launched via Firewatir) so I want to put in code that
> first checks for any existing Firefox processes and issues a kill to
> their PIDs.
>
> I'm really new to Ruby -- how can I best accomplish this?  Thanks.

gem install sys-proctable

Regards,

Dan
7067095abfc198a023c3a9b5e31e67ea?d=identicon&s=25 Peter Booth (peterbooth)
on 2009-03-31 20:31
(Received via mailing list)
It's OS specific. `killall Firefox` is a good place to start.
This topic is locked and can not be replied to.