fork这个单词在英文中原义是分岔,例如河流、道路一分为二的分岔口,作为物品则有叉子、耙子的意思。
a place where a road, river, etc. divides into two parts, or either of those two parts.
了解这一层英文含义更以利于我们理解fork()这个系统调用的作用:将进程一分为二,复制出一份完全相同的新进程,并作为原进程的子进程。
以下是fork()系统调用在man手册中的标准定义:
fork() creates a new process by duplicating the calling process. The new process is referred to as the child process. The calling process is referred to as the parent process.
在仅使用fork的情况下,一个常见的面试问题是:给你一段代码,分析执行后一共有多少个进程。