---
title: "What is ppid"
description:
  "A look at how process ids are linked up and maintain the hierarchy."
canonical_url: "https://www.bigbinary.com/blog/what-is-ppid"
markdown_url: "https://www.bigbinary.com/blog/what-is-ppid.md"
---

# What is ppid

A look at how process ids are linked up and maintain the hierarchy.

- Author: Neeraj Singh
- Published: September 21, 2013
- Categories: Ruby

In [previous blog](do-not-allow-force-push-to-master) we discussed ruby code
where we used two things: `ppid` and `ps -ocommand`. In this blog let's discuss
`ppid`. `ps -ocommand` is discussed in the
[next blog](getting-arguments-passed-to-command).

## Parent process id is ppid

We know that every process has a process id. This is usually referred as `pid`.
In \*nix world every process has a parent process. And in ruby the way to get
the "process id" of the parent process is through `ppid`.

Let's see it in action. Time to fire up irb.

```plaintext
irb(main):002:0> Process.pid
=> 83132
irb(main):003:0> Process.ppid
=> 82455
```

Now keep the irb session open and go to anther terminal tab. In this new tab
execute `pstree -p 83132`

```plaintext
$ pstree -p 83132
-+= 00001 root /sbin/launchd
 \-+= 00151 nsingh /sbin/launchd
   \-+= 00189 nsingh /Applications/Utilities/Terminal.app/Contents/MacOS/Terminal -psn_0_45067
     \-+= 82452 root login -pf nsingh
       \-+= 82455 nsingh -bash
         \--= 83132 nsingh irb
```

If `pstree` is not available then you can easily install it using
`brew install pstree`.

As you can see from the output the process id 83132 is at the very bottom of the
tree. The parent process id is 82455 which belongs to "bash shell".

In irb session when we did `Process.ppid` then we got the same value 82455.

## Links

- [Human page](https://www.bigbinary.com/blog/what-is-ppid)
