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

E

Eric Milford

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.
 
G

Glen Holcomb

I would just use the system for it. But if you really want to do it in Rub=
y
you could do something like this:

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

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


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.


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

-Greg Graffin (Bad Religion)
 
D

Daniel Berger

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? =A0Thanks.

gem install sys-proctable

Regards,

Dan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top