6 Difference Between Fork ( )And Exec( )

SHARE

What Is Fork ( )?

Fork is a function in UNIX operating system that is used to generate a duplicate of particular process by creating two simultaneous executing processes of a program. These two processes are typically called the ‘’parent’’ and ‘’child’’ processes. They use multitasking protocols to share system resources.

When fork creates a new process by copying the current process, it performs a copy-o-write. This means that the memory of the new process is shared with the parent process until it is changed. When the memory is changed, the memory gets copied to make sure each process has its own valid copy of the memory.

What You Need To Know About Fork

  1. Fork is a function in UNIX operating system that is used to generate a duplicate of particular process by creating two simultaneous executing processes of a program.
  2. The fork system call generates a duplicate copy of the calling process.
  3. The new process created by a fork system call is identical to the parent process in almost all respect.
  4. After the fork system call, both the child and parent processes will be executed simultaneously.
  5. In fork, the parent and the child processes are in different address spaces.
  6. Example: int process_id=fork();

What Is Exec ( )?

Exec is a functionality of an operating system that runs an executable file in the context of an already existing process, replacing the previous executable. This act is also referred to as an overlay. It is especially important in Unix-like systems, although exists elsewhere. As a new process is not created, the process identifier does not change, but the machine code, data heap and stack of the process are replaced by those of the new program.

The exec system call is used to execute a file which is residing in an active process. When exec is called, the previous executable file is replaced and new file is executable. More precisely, we can say that using exec system call will replace the old file or program from the process with a new file or program.  

What You Need To Know About Exec 

  1. Exec is an operation in a UNIX operating system that creates a process by replacing the previous process.
  2. The exec system call is used to replace the entire current calling processes with a new program altogether.
  3.  The new program which replaces the current process is loaded and is run from the entry point.
  4. After the exec system call the control never get transferred to the original program until and unless an exec () error does not happen.
  5. In exec, the child address space replaces the parent address space.
  6. Example: int execvp (const char *file_name, char*const argv[])

Difference Between Fork And Exec In Tabular Form

BASIS OF COMPARISON FORK EXEC
Description Fork is a function in UNIX operating system that is used to generate a duplicate of particular process by creating two simultaneous executing processes of a program.   Exec is an operation in a UNIX operating system that creates a process by replacing the previous process.  
System Call The fork system call generates a duplicate copy of the calling process.   The exec system call is used to replace the entire current calling processes with a new program altogether.  
New Process/Program The new process created by a fork system call is identical to the parent process in almost all respect.   The new program which replaces the current process is loaded and is run from the entry point.  
After System Call After the fork system call, both the child and parent processes will be executed simultaneously.   After the exec system call the control never get transferred to the original program until and unless an exec () error does not happen.  
Parent And The Child Processes In fork, the parent and the child processes are in different address spaces.   In exec, the child address space replaces the parent address space.  
Example int execvp (const char *file_name, char*const argv[]) int execvp (const char *file_name, char*const argv[])