# How to know the childs PID of a given process?

**URL:** <https://www.ruby-forum.com/t/how-to-know-the-childs-pid-of-a-given-process/181045>\
**Category:** Ruby\
**Created:** [January 4, 2010, 12:32pm UTC](https://www.ruby-forum.com/t/how-to-know-the-childs-pid-of-a-given-process/181045 "2010-01-04T12:32:52Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ISSSSaki\_Baz\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/51bf81/32.png) [@ISSSSaki\_Baz\_C](https://www.ruby-forum.com/u/ISSSSaki_Baz_C)\
**Post date:** [January 4, 2010, 12:32pm UTC](https://www.ruby-forum.com/t/how-to-know-the-childs-pid-of-a-given-process/181045/1 "2010-01-04T12:32:52Z")

</div>

Hi, I know that a Ruby process with PID 1000 (under Linux) has forked 4  
times.  
How could I know the PID of those childs from any other ruby  
interpreter?  
This is, I just know the PID of the parent (1000).

Of course I could do some hack as inspecting the output of “ps” and  
inspecting  
the pid/ppid, but I’d prfer a ppure Ruby method for this.

Thanks for any suggestion.

---

<div class="post-metadata">

**Author:** ![ISSSSaki\_Baz\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/51bf81/32.png) [@ISSSSaki\_Baz\_C](https://www.ruby-forum.com/u/ISSSSaki_Baz_C)\
**Post date:** [January 4, 2010, 2:21pm UTC](https://www.ruby-forum.com/t/how-to-know-the-childs-pid-of-a-given-process/181045/2 "2010-01-04T14:21:10Z")

</div>

On 01/04/2010 11:52 AM, Iñaki Baz C. wrote:

> Hi, I know that a Ruby process with PID 1000 (under Linux) has forked 4 times.  
> How could I know the PID of those childs from any other ruby interpreter?  
> This is, I just know the PID of the parent (1000).
> 
> Of course I could do some hack as inspecting the output of “ps” and inspecting  
> the pid/ppid, but I’d prfer a ppure Ruby method for this.
> 
> Thanks for any suggestion.

The typical approach is that the forking parent records PIDs of its  
children. If that information needs to be propagated you can either  
write it to a file or make it available via DRb.

If you need multiple Ruby processes to collaborate I would probably turn  
to DRb anyway. In that case you might not even need to record PIDs but  
you could have a coordinator where processes register and unregister or  
which starts processes itself. It depends on your use case.

Kind regards

robert

---

<div class="post-metadata">

**Author:** ![ISSSSaki\_Baz\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/51bf81/32.png) [@ISSSSaki\_Baz\_C](https://www.ruby-forum.com/u/ISSSSaki_Baz_C)\
**Post date:** [January 4, 2010, 3:22pm UTC](https://www.ruby-forum.com/t/how-to-know-the-childs-pid-of-a-given-process/181045/3 "2010-01-04T15:22:02Z")

</div>

El Lunes, 4 de Enero de 2010, Robert K.  
escribió:\> The typical approach is that the forking parent records PIDs of its

> children. If that information needs to be propagated you can either  
> write it to a file or make it available via DRb.
> 
> If you need multiple Ruby processes to collaborate I would probably turn  
> to DRb anyway. In that case you might not even need to record PIDs but  
> you could have a coordinator where processes register and unregister or  
> which starts processes itself. It depends on your use case.

Thanks a lot. The fact is that I’d like not to modify the program whose  
processes I want to monitor, so I was looking for something as “ps”.

Thanks a lot.

---

<div class="post-metadata">

**Author:** ![ISSSSaki\_Baz\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/51bf81/32.png) [@ISSSSaki\_Baz\_C](https://www.ruby-forum.com/u/ISSSSaki_Baz_C)\
**Post date:** [January 4, 2010, 4:34pm UTC](https://www.ruby-forum.com/t/how-to-know-the-childs-pid-of-a-given-process/181045/4 "2010-01-04T16:34:01Z")

</div>

On Jan 4, 7:21 am, Iñaki Baz C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Thanks a lot. The fact is that I’d like not to modify the program whose  
> processes I want to monitor, so I was looking for something as “ps”.

> **[GitHub - djberg96/sys-proctable: A cross-platform Ruby interface for...](https://github.com/djberg96/sys-proctable)**
>
> A cross-platform Ruby interface for gathering process information on your operating system - GitHub - djberg96/sys-proctable: A cross-platform Ruby interface for gathering process information on yo...

Regards,

Dan

---

<div class="post-metadata">

**Author:** ![ISSSSaki\_Baz\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/51bf81/32.png) [@ISSSSaki\_Baz\_C](https://www.ruby-forum.com/u/ISSSSaki_Baz_C)\
**Post date:** [January 4, 2010, 4:51pm UTC](https://www.ruby-forum.com/t/how-to-know-the-childs-pid-of-a-given-process/181045/5 "2010-01-04T16:51:35Z")

</div>

El Lunes, 4 de Enero de 2010, Daniel B.  
escribió:

> [GitHub - djberg96/sys-proctable: A cross-platform Ruby interface for gathering process information on your operating system](http://github.com/djberg96/sys-proctable)

There is a typo in the README:

gem install sys-proctalbe --platform linux # Linux

(note “proctalbe”) 😉

---

<div class="post-metadata">

**Author:** ![ISSSSaki\_Baz\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/51bf81/32.png) [@ISSSSaki\_Baz\_C](https://www.ruby-forum.com/u/ISSSSaki_Baz_C)\
**Post date:** [January 4, 2010, 4:49pm UTC](https://www.ruby-forum.com/t/how-to-know-the-childs-pid-of-a-given-process/181045/6 "2010-01-04T16:49:50Z")

</div>

El Lunes, 4 de Enero de 2010, Daniel B.  
escribió:\> \> \>

> > Thanks a lot. The fact is that I’d like not to modify the program whose  
> > processes I want to monitor, so I was looking for something as “ps”.
> 
> [GitHub - djberg96/sys-proctable: A cross-platform Ruby interface for gathering process information on your operating system](http://github.com/djberg96/sys-proctable)

Really interesting, thanks a lot!
