question about the system method

J

Jarod Zhu

Hi, all

I want to use system method to run a background process, like

system("ruby deamon.rb") # the deamon.rb runs a dead loop

When my main process ends, I want to end the background process
too.

How can I do it?

If I can get the pid of background process, I can use
Process.kill. But the system method dosen't return the pid.

Does anyone here know the solution?

Thank you

Jarod Zhu
 
A

Avdi Grimm

Hi, all

I want to use system method to run a background process, like

system("ruby deamon.rb") # the deamon.rb runs a dead loop

When my main process ends, I want to end the background process
too.

How can I do it?

The basic answer is to use IO.popen() - see
http://www.ruby-doc.org/core/classes/IO.html#M002267

For more advances applications you may want to take a look at Daemons:
http://daemons.rubyforge.org/

--
Avdi

Home: http://avdi.org
Developer Blog: http://avdi.org/devblog/
Twitter: http://twitter.com/avdi
Journal: http://avdi.livejournal.com
 

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
474,184
Messages
2,570,973
Members
47,527
Latest member
RoxanneTos

Latest Threads

Top