Parent and Child Processes

Processes have strange terminology, we can talk about a parent and child process and isn’t that weird? We’re talking about processes, not cats!

A process can start another process. Your bash shell starts another process anytime you run a command. Your command was started by that bash process. That bash shell is the parent process to any process you create. And any process you create is the child process of that bash shell.

I keep typing process over and over. So I just have to say…

…process.

Anyway, processes start processes and are started by processes. The great granddaddy of all processes is called the init process. Your init process has the processes id of 1 since it’s the first thing started when a system boots up and all processes are the child (or grandchild or great grand child or… you get the idea) of that process.

ps, that very useful command, has a combination of flags that lets us see parent and child relationships.

Alpha:~ computerlamp$ ps fa
  PID TTY      STAT   TIME COMMAND
 9767 pts/2    Ss     0:00 -bash
 9775 pts/2    R+     0:00  \_ ps fa

You can see where bash started the command ps fa. For another layer, I typed bash then I did ps fa again.

Alpha:~ computerlamp$ bash
Alpha:~ computerlamp$ ps fa
 PID TTY      STAT   TIME COMMAND
 9767 pts/2    Ss     0:00 -bash
11442 pts/2    S      0:00  \_ bash
11511 pts/2    R+     0:00      \_ ps fa

The bash shell is the parent of the bash shell which is the parent of the ps fa command.

Another way to do this is with ps -ejH. This time, the results look different.

Alpha:~ computerlamp$ ps -ejH
  PID  PGID   SID TTY          TIME CMD
 9767  9767  9767 pts/2    00:00:00 bash
12398 12398  9767 pts/2    00:00:00   ps

It does the same thing, but this version doesn’t have the lines that the first version does.

And in conclusion, process!

 

Leave a Reply

Your email address will not be published. Required fields are marked *