Orphan Process using Code example

Kartik Siddhabathula
The Startup
Published in
4 min readFeb 23, 2021

--

Fig 1: Angelina Jolie with her 3 adopted kids who were orphans (PC: Google)

Orphans in the real world are very unfortunate victims of fate. Loosing parents is very unfortunate and exposes a child to unforeseen many other problems. There are many human problems we may solve like poverty or hunger but we can never have a world where no child becomes an orphan and looses parent’s love and care.

Real world scenarios are to some extent reflected in the linux operating system. There are processes in linux that also become orphans i.e. the parent process of the child process terminates, but the child is still executing. This article is not intended to give the definition and go over the nuanced details. The intention of the article is to show through code the re-parenting of the orphaned process in linux.

Processes exist in a parent child relationship in the world of linux. Processes also go through different state during their life time i.e. from their creation to termination. If a process terminates while its child processes are still executing, then the child process will become an orphan process. Processes that become orphans in the world of linux are fortunate compared to their human counterparts that they get adopted by the init process which has process ID of 1. In fig 2, we can see the code where we are creating a child and printing its parent’s ID. After sometime, we terminate the parent process and then in the output we can see…

--

--

Kartik Siddhabathula
The Startup

Sr. SDET, Starbucks | Previously Asst Prof | Love traveling, reading history and stories from around the world | Selenophile | Photography.