【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 导读和注意事项 各位技术爱好者,看完本文后,你可 ...
随机推荐
- 第十三天笔记Cookie
第十三天笔记Cookie 计算机重要的四个内容 数据结构 数据存储的结构及逻辑的体现,以及相关数据结构之间的操作(算法) 操作系统 windows(dos命令).linux(指令操作) 计网 网络通信 ...
- Kubernetes-yaml详解
目录: Yaml语法格式 查看api资源版本标签 deployment模板 service模板 查询帮助和格式指令 Pod模板 写 yaml太累怎么办 yaml文件的学习 方法 deployment. ...
- iOS笔记 - Runtime 01:前期准备(isa结构 | Class结构 | 方法缓存)
前言 1 - OC机制很多都是基于 Runtime实现的,比如指针的弱引用.OC的消息机制属于 Runtime的一部分 2 - OC是一门动态语言,在程序运行过程中就可以修改已经编译好的代码 3 - ...
- Andorid 悬浮窗的适配指北
我们有时候需要显示一个悬浮窗,悬浮窗由服务开启,里面会有一些操作 但是我在开发时遇到高版本 Android12 和低版本4.4 ,显示不一样的地方 这边整理了下适配的方法方案 一:根据版本不一的时候, ...
- pandas通过sqlalchemy写入pgsql报错can't adapt type 'numpy.int64'
其实以前也遇到过,后来不了了之,但今天又出现了,还是大概记录下. 我个人习惯按我自己的理解搞事情,只要结果对就行,但不一定对. 分析下原因,突然想到dataframe中有一列全是列表,列表中全是整数, ...
- 【小记】如果 golang 内存不够了怎么办
在看 redis 1.0 源码时,总会看到需要申请内存的地方,如果申请不到需要大的内存就会返回 NULL,然后在调用层抛出 oom. 比如 listDup 中在复制特殊 value 或者加入新节点时都 ...
- COM三大接口:IUnknown、IClassFactory、IDispatch。
(1)COM组件有三个最基本的接口类,分别是IUnknown.IClassFactory.IDispatch. COM规范规定任何组件.任何接口都必须从IUnknown继承,IUnknown包含三个函 ...
- mybatis自增主键的获取
实体类 package org.example.entity; public class User { private Integer id; private String name; private ...
- plsql和instantclient版本都对,依然不能初始化oci.dll解决办法
这里写到 "初始化错误,不能初始化 oci.dll, 请确认你安装的是64位的Oracle客户端 " ,这个描述还是非常的到位啊,我一检查,果然下载的客户端是32位的,在确保自己的 ...
- VMWare 12 Mac 10.11 XCode 7.3 Ipad真机调试重要问题总结
XCode 7.3可以不需要每年缴费而直接调试IOS应用,测试如下: 1,安装Mac 10.11在VMWare12上,网上有很多例子.注意: 1.1,虚拟机设置中USB为USB2.0,不能是3.0或其 ...