Checking whether or not a process is the child of another

Whenever fork() is called the process in which the fork()
statement is executed spawns a child process.

In a program that has yet to call fork() has only one running
process, or one unit of execution.

When fork() returns, there are two processes running
concurrently.

Both of these processes have the same call-stack immediately after
fork() returns. In the parent process, the return value of fork() is
the PID of the child process. In the child process, the return value
of fork() is 0.

➜ ~ ./a.out
I am the parent process. My PID is 13728
which can also be retrieved using getpid(): 13728
Parent process terminating
I am the child process. My PID is 13729
My parent's PID is 13728
which can also be retrieved using getppid(): 13728
Child process terminating

The PID numbers may vary each time you run the program. The
execution-order between the two processes is not guaranteed meaning
that the parent process will return to the shell before the child
process has finished, which is why we traditionally use waitpid().

Checking if a process is the "main" process

One can use syscall to find out whether or not a process is the "main" one like so,