Hi,
if I start a process in Ruby using the system(“some process”)
how can I get the process id of the process I’ve just started?
Cheers.
Dan.
Hi,
if I start a process in Ruby using the system(“some process”)
how can I get the process id of the process I’ve just started?
Cheers.
Dan.
Fish Man wrote:
Hi,
if I start a process in Ruby using the system(“some process”)
how can I get the process id of the process I’ve just started?Cheers.
Dan.
Dear Fish Man,
This is very simple.Just you can use Process.pid.
For instance,
I wll give some example,
I am having one file:
1.rb
system(“ps”) =>execute the process
p Process.pid =>it will tell the current process Id.
./1.rb
Next you can ruby this program.
You can see this output:
PID TTY TIME CMD
18662 pts/2 00:00:00 bash
18962 pts/2 00:00:00 ruby
18963 pts/2 00:00:00 ps
18962
You can combine the ruby process id and last one id is there.Both
are same.
This is way only we can take the process id.Other than that I don’t
know.
by
vellingiri.
On Oct 25, 2007, at 7:25 AM, Arul hari wrote:
For instance,
I wll give some example,
I am having one file:
1.rb
system(“ps”) =>execute the process
p Process.pid =>it will tell the current process Id.
But not the one launched by system.
You probably want to use something other than system – popen, fork/
exec, something like that
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs