Pricess ID

F

Fish Man

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

Arul hari

Fish said:
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.
 
A

Aria Stewart

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.

But not the one launched by system.

You probably want to use something other than system -- popen, fork/
exec, something like that
 

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,269
Messages
2,571,338
Members
48,028
Latest member
chasetony

Latest Threads

Top