【Operating System】——An interesting question on Process Creation
In the book Operating System Concepts- 9th Edition - Chapter 3 - Page 117 - Page 120 it says:


How do we understand this concept? There is an answer getting from Stack Overflow:
operating system - Creation of A New Process in an OS - Stack Overflow
Whenever a processor(CPU) runs a program , it stores the line number of the code it is executing (more formally address pointing to that instruction).The computer stores it in a register (kind of variable) called as stack pointer. So the stack pointer(SP) will store the current instruction processor has to execute (or run). This way computer track which instruction should be executed .
When a program runs , it is allocated some small memory in the computer's main memory.Here's where all our code along with important registers(including SP) which help processor to keep track of program when it's running.To a process is uniquely identified by Process ID(PID).
Now let me come to your question. Whenever we call fork , a copy of the program from which you called fork is created. This copy is called as the "child process" and our original process is known as parent process.
When the copy created , all the memory that your program has been allocated is copied to some other place in memory (which is now child process's memory).So an identical running program(process) is created.
Now this copied memory contains the SP of the parent process , so whenever processor runs the program it directly runs the program from the same fork call line (since SP will store this line as current instruction when the process is created).Since our fork call was successful , it has to return a non-negative value (denoting success of fork system call)So it return 0 to the child process and child process ID to the parent(since the current Process ID was pointing here too).
Returning Child Process ID to parent makes a good deal since it's better that parent can keep a track of child process created from it.Too returning child a 0 make the deal even better as we have to return a non-negative number and other positive number may be some process's PID.
Run cd /proc in your linux system . All the directories having some numeral name are pid of some process(which may be active/inactive).Read more about it to clear the concept.
【Operating System】——An interesting question on Process Creation的更多相关文章
- 【Teradata System】How Teradata uses MPP Systems
内存分配 内存初始化时将分配给操作系统和Vprocs,内存不使用部分的90%做为FSG (File Segment Cache) ,由PDE对FSG进行管理. FSG Cache:缓存常驻内存的dat ...
- 80端口被系统服务【kernel&System】占用解决方案
netstat -ano | findstr port //查看端口占用情况 tasklist | findstr port //查看端口被占用的具体服务名 运行net stop http ...
- 60款开源云应用【Part 2】(60 Open Source Apps You Can Use in the Cloud)
60款开源云应用[Part 2](60 Open Source Apps You Can Use in the Cloud) 本篇翻译自http://www.datamation.com/open-s ...
- 如何定位“Operating system error 32(failed to retrieve text for this error. Reason: 15105)”错误中被占用的文件
之前在这篇"Operating system error 32(failed to retrieve text for this error. Reason: 15105)"博 ...
- Operating system error 32(failed to retrieve text for this error. Reason: 15105)
一台数据库服务器的事务日志备份作业偶尔会出现几次备份失败的情况,具体的错误信息为: DATE/TIME: 2018/7/30 12:10:52 DESCRIPTION: BackupDiskFi ...
- Operating system management of address-translation-related data structures and hardware lookasides
An approach is provided in a hypervised computer system where a page table request is at an operatin ...
- 【C/C++】Linux下使用system()函数一定要谨慎
[C/C++]Linux下使用system()函数一定要谨慎 http://my.oschina.net/renhc/blog/53580 曾经的曾经,被system()函数折磨过,之所以这样,是因为 ...
- 【C/C++】Linux下system()函数引发的错误
http://my.oschina.net/renhc/blog/54582 [C/C++]Linux下system()函数引发的错误 恋恋美食 恋恋美食 发布时间: 2012/04/21 11:3 ...
- 【63.73%】【codeforces 560A】Currency System in Geraldion
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【等待事件】等待事件系列(3+4)--System IO(控制文件)+日志类等待
[等待事件]等待事件系列(3+4)--System IO(控制文件)+日志类等待 1 BLOG文档结构图 2 前言部分 2.1 导读和注意事项 各位技术爱好者,看完本文后,你可 ...
随机推荐
- skype网络异常无法登录
在有些win7电脑上安装最新版skype软件后,打开skype软件后显示无法访问网络 检查网络及防火墙,确定无异常 最后排查原因定位到操作系统的根证书 发现系统缺少部分DigiCert的根证书 从其他 ...
- docker0 flannel.1不在同一网段
现象: docker0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 172.17.0.1 netmask 255.2 ...
- 在windows 7下构建 FTP 服务器
首先我们在C盘建立两个文件夹,用于发ftp的上传和下载 其次我们找到控制面板>程序>打开或关闭windows功能 进入后找到Internet 信息服务>FTP服务器>确定! 选 ...
- 如何手动安装python模块包package
我们不用Cd C:\Users\xxx.xx\AppData\Local\Programs\Python\Python311 Python -m pip install openpyxl的方法. 解答 ...
- [Jquery]如何绑定相同id的所有元素?
Jquery中相同的id不能用$()获得,只能获得第一个匹配的元素. 原因:id不可重复 解决方案: 方案1: 通过 $("input[id='xxxx']"); 可以选择多个相同 ...
- 【广告】UEOI 招聘减章
欢迎加入UEOI! 招聘目标:>=25人 各位++rp.
- List<Object>转为对象
List<Object> list = new ArrayList<>(); List<BMSQ> bmsqList = (List<BMSQ>)(Li ...
- How to Avoid Trivial Solutions in Physics-Informed Neural Networks
未发表(2021) 本文也是关注采样点的一篇工作.主要从PINN的性能与采样点数量的关系方面入手考虑.提出了一个新的惩罚项,并对采样策略提出了一点看法. 本文的工作相对比较直观,简单,效果可能并不是很 ...
- beanshell脚本构造生成随机大小的文件
文件下载地址:链接: https://pan.baidu.com/s/1wum8hfBeLMipdtQlqysp8A?pwd=8e7r 提取码: 8e7r #!/bin/bash -e # sh fi ...
- Anaconda配置环境变量
环境变量里写自己的Anaconda下载目录,找到对应的文件位置,然后把这三个上移到最上面,点击确定即可配置完成 出现这个环境变量就成功啦 在输入conda 出现这个就表明你的Anaconda已经好了