How to create a process in Linux – Process creation and System Calls


Have you ever wondered what happens behind the scenes when we run any command in Linux ??

Have you ever wondered how does it print out the value in the terminal ??

What do we refer to by system calls ??

 

No, let’s find that out. 😉 How to create a process in Linux?


How to create a process in Linux

 

What is a process ?
Any running program’s instance is known as a process.

 

What happens in the background when a process is created ?
A fork() call is generated whenever a new process is created and in return it creates two processes with the same address namespace. Then, exec() call loads the new program in the child process and executes it.

 

 


Thereafter, if the command/program executed successfully, then the program exits by exit() system call. The process remains in the “Zombie” state in the process table until the parent process reaps the status of its child process.


A parent process reaps its child through the wait() system call( you can refer the image above to understand it in a better way.


Now, there is one more state which is often asked by interviewers in the interviews and that is “Orphaned state or processes”


What are Orphaned processes ?
When parent process exits or dies before the child process, this is the state when process is called as Orphaned. When a process is orphaned, it is owned by the init process [ the first one in the process tree ].



Hope, you liked this information. Stay tuned and check out our new Linux blogs also. Happy learning!

1 thought on “How to create a process in Linux – Process creation and System Calls”

Leave a Reply

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