Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how many ways we can create a process in linux using c

Tags:

c

linux

shell

I have confusion in creating a process in Linux. Up to now I thought that we can create the process by calling the following system calls.

  1. system()
  2. exec() family of system call
  3. fork() system call

but:

  1. system(): But as "system" system call executing the input executable on shell and shell is creating a child process for the execution of input .here shell is calling child process then we can say that fork is creating process for this.

  2. exec family of system call: As this family of system call over write the current running process with new process.So it is also creating a new process but using same address space. As I think it is also calling call fork for creating the process.

I am confused with the fact all the above is possible way of creating a new process or only fork system.

like image 432
Rajdhar Avatar asked Jan 18 '14 14:01

Rajdhar


1 Answers

exec family of system call does not call fork, neither it creates a new process. It only overwrites the existing process with the new binary.

In linux user programs, fork is the only function to create new process. Though fork internally calls clone and other system calls.

In other hands, system is only a wrapper to fork and exec. The actual task of creating a process is done by fork in system. So system is not a way to create new process.

like image 88
Dipto Avatar answered Oct 20 '22 03:10

Dipto