官术网_书友最值得收藏!

fork()

Fork() is one of the core "Unix thread APIs" available across *nix systems since the inception of legacy Unix releases. Aptly named, it forks a new process from a running process. When fork() succeeds, the new process is created (referred to as child) by duplicating the caller's address space and task structure. On return from fork(), both caller (parent) and new process (child) resume executing instructions from the same code segment which was duplicated under copy-on-write. Fork() is perhaps the only API that enters kernel mode in the context of caller process, and on success returns to user mode in the context of both caller and child (new process).

Most resource entries of the parent's task structure such as memory descriptor, file descriptor table, signal descriptors, and scheduling attributes are inherited by the child, except for a few attributes such as memory locks, pending signals, active timers, and file record locks (for the full list of exceptions, refer to the fork(2) man page). A child process is assigned a unique pid and will refer to its parent's pid through the ppid field of its task structure; the child’s resource utilization and processor usage entries are reset to zero.

The parent process updates itself about the child’s state using the wait() system call and normally waits for the termination of the child process. Failing to call wait(), the child may terminate and be pushed into a zombie state.

主站蜘蛛池模板: 杂多县| 夏邑县| 桐城市| 肥乡县| 日照市| 北海市| 曲靖市| 缙云县| 宜丰县| 凭祥市| 崇礼县| 扎兰屯市| 龙州县| 水城县| 阿克陶县| 宁河县| 肃南| 阿克苏市| 霍城县| 玉树县| 天全县| 介休市| 崇文区| 德令哈市| 彭山县| 永安市| 磐石市| 阿合奇县| 邛崃市| 惠州市| 牙克石市| 兰州市| 龙口市| 青海省| 徐闻县| 满城县| 成安县| 湖北省| 平陆县| 扶绥县| 阿拉尔市|