📜  fork()和vfork()之间的区别

📅  最后修改于: 2021-08-24 04:44:08             🧑  作者: Mango

1. fork():
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.