📜  fork() 和 vfork() 的区别

📅  最后修改于: 2021-09-11 03:34:23             🧑  作者: Mango

1.叉():
Fork() 是用于创建新进程的系统调用。由 fork() 系统调用创建的新进程称为子进程,调用 fork() 系统调用的进程称为父进程。子进程的代码与其父进程的代码相同。创建子进程后,父进程和子进程都从 fork() 之后的下一条语句开始执行,并且两个进程同时执行。

2. vfork() :
Vfork() 也是用于创建新进程的系统调用。由 vfork() 系统调用创建的新进程称为子进程,调用 vfork() 系统调用的进程称为父进程。子进程的代码与其父进程的代码相同。子进程暂停父进程的执行,直到子进程完成其执行,因为两个进程共享相同的地址空间。

fork() 和 vfork() 的区别:

S.No. FORK() VFORK()
1. In fork() system call, child and parent process have separate memory space. While in vfork() system call, child and parent process share same address space.
2. The child process and parent process gets executed simultaneously. Once child process is executed then parent process starts its execution.
3. The fork() system call uses copy-on-write as an alternative. While vfork() system call does not use copy-on-write.
4. Child process does not suspend parent process execution in fork() system call. Child process suspends parent process execution in vfork() system call.
5. Page of one process is not affected by page of other process. Page of one process is affected by page of other process.
6. fork() system call is more used. vfork() system call is less used.
7. There is wastage of address space. There is no wastage of address space.
8. If child process alters page in address space, it is invisible to parent process. If child process alters page in address space, it is visible to parent process.