Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting the parent id of a given process in Ruby

How do you get the parent process id of a process that is not the current process in Ruby?

I've checked Ruby's Process module, but it only seems to provide a means to access the PPID of the current process.

I also checked google for anything on the subject, but the first two pages seemed to only contain links regarding how to use the aforementioned Process module.

I was hoping to do this without having to rely too much on the underlying OS, but whatever works.

like image 889
Alexej Magura Avatar asked Oct 27 '25 15:10

Alexej Magura


1 Answers

Shell out:

1.9.3p429 :001 > `ps -p 7544 -o ppid=`.strip
 => "7540"
like image 64
substars Avatar answered Oct 29 '25 05:10

substars