In fork a new address space is created for the child process, whereas in the exec family the process's address space remains same. In exec, the process is replaced whereas in fork a new process is created. All the process segments of the previous process in exec are freed and new memory segments are allocated. The main thing is that the pid remains the same in exec whereas in fork there's a new pid for the child process.
Fork is used to create new process, where it duplicates the current process and creates the new one along with he old process. The created new process will use the same process context of the parent process but has its own data space, enivronment and file descriptors. Fork returns pid of the created new process on success, -1 on the failure and 0 when the new process executes the fork. syntax: fork(); Whereas the exec family is used to create a new process by replacing the old process. Newly created process will be replace the process context of the old process and the task structure of the old process will be taken over by the new process. Execl returns nothing on sucess and -1 on the failure. syntax : execl(char* path, char* filename, char* arg1..., char* argn, NULL);
FORK() is used to create a new process . Its duplicate the current process and create a new process together with old process. The new process shares the process context of the old process but the new process consists of its own data block and vice versa. During execution of fork its return pid of new process , in case of failure its return -1 and when the new process is execute fork again its return 0.
EXEC family is used to replace current working process with the new one .The new process hijack the old process together with process context and the task structure where everything is replaced with the new one.
when using execl() during success its return nothing but in failure its return -1.
Fork is system call which used to create a new process, It does not take an argument . The process which invokes the Fork() is known as the parent process and the new process is called the child process. when fork system call is made , the operating system generates a copy of the parent process which become the child process and the operating system will pass most of the information of parent process to the child process but some information is unique to the child process which is child has its own process ID (PID) and child will have a different PPID (Parent PID) than its parent .
when Fork is executed by the parent it returns the PID of new process and -1 on failure and when again executed by the child it returns 0.
Exec is used to replaces the current process with a new process. The new process replaces the text, data and stack segment of the old process with the new one . And only the user area of the process remains the same.