
Linux System Programming Techniques
By :

Understanding what orphans are in a Linux system is just as crucial as understanding zombies. This will give you a deeper understanding of the entire system and how processes get inherited by systemd
.
An orphan is a child whose parent has died. However, as we have learned in this chapter, every process needs a parent process. So, even orphans need a parent process. To solve this dilemma, every orphan gets inherited by systemd
, which is the first process on the system—PID 1
.
In this recipe, we'll write a small program that forks, thus creating a child process. The parent process will then exit, leaving the child as an orphan.
Everything you need for this recipe is listed in the Technical requirements section of this chapter.
In this recipe, we will write a short program that creates an orphan process that will be inherited by systemd
. Let's get started: