Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
freem
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Openai/6911cc4b-5d54-800b-88ae-dc7ac6ff2d3d
(section)
Add languages
Page
Discussion
English
Read
Edit
Edit source
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
Edit source
View history
General
What links here
Related changes
Special pages
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
====== 五、 fork() 函数 ====== * '''问题背景:''' 由于 exec() 会替换当前进程,如果在循环中直接调用 exec(),程序只会执行一次 exec() 就会终止 。 * '''功能:''' fork() 系统调用会'''克隆'''当前进程,创建一个新的子进程 。父进程和子进程会从 fork() 调用后的同一行代码开始执行 。 * '''返回值区分:''' * '''子进程 (Child Process):''' fork() 返回 '''0''' 。 * '''父进程 (Parent Process):''' fork() 返回 '''非零值'''(即子进程的PID)。 * '''失败:''' fork() 返回 '''-1''' 。 * '''fork() + exec() 模式:''' 在 '''子进程''' 中调用 exec() 函数来替换自身运行新程序,从而允许 '''父进程''' 继续运行,实现并发或连续操作 。 * '''效率技巧:''' 操作系统使用“写时复制”(copy on-write)技术,父子进程最初共享数据,只有当其中一方尝试修改数据时,系统才会进行复制. * '''平台限制:''' Windows 系统本身不支持 fork(),但在 Cygwin 等环境中可以通过模拟实现 。 我最近学习了这些知识点,请使用苏格拉底方式提问我,一次一个问题
Summary:
Please note that all contributions to freem are considered to be released under the Creative Commons Attribution-ShareAlike 4.0 (see
Freem:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)