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的更多相关文章

  1. 【Teradata System】How Teradata uses MPP Systems

    内存分配 内存初始化时将分配给操作系统和Vprocs,内存不使用部分的90%做为FSG (File Segment Cache) ,由PDE对FSG进行管理. FSG Cache:缓存常驻内存的dat ...

  2. 80端口被系统服务【kernel&System】占用解决方案

    netstat -ano | findstr port    //查看端口占用情况 tasklist | findstr port   //查看端口被占用的具体服务名 运行net stop http ...

  3. 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 ...

  4. 如何定位“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)"博 ...

  5. Operating system error 32(failed to retrieve text for this error. Reason: 15105)

    一台数据库服务器的事务日志备份作业偶尔会出现几次备份失败的情况,具体的错误信息为: DATE/TIME:    2018/7/30 12:10:52 DESCRIPTION: BackupDiskFi ...

  6. 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 ...

  7. 【C/C++】Linux下使用system()函数一定要谨慎

    [C/C++]Linux下使用system()函数一定要谨慎 http://my.oschina.net/renhc/blog/53580 曾经的曾经,被system()函数折磨过,之所以这样,是因为 ...

  8. 【C/C++】Linux下system()函数引发的错误

    http://my.oschina.net/renhc/blog/54582 [C/C++]Linux下system()函数引发的错误 恋恋美食  恋恋美食 发布时间: 2012/04/21 11:3 ...

  9. 【63.73%】【codeforces 560A】Currency System in Geraldion

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  10. 【等待事件】等待事件系列(3+4)--System IO(控制文件)+日志类等待

     [等待事件]等待事件系列(3+4)--System IO(控制文件)+日志类等待   1  BLOG文档结构图     2  前言部分   2.1  导读和注意事项 各位技术爱好者,看完本文后,你可 ...

随机推荐

  1. vue2 安装swiper

    npm install swiper@5.4.5 -D

  2. [部署日记]GO在Visual Studio Code初次运行时提示The "gopls" command is not available. Run "go get -v golang.org/x/tools/gopls" to install.

    本以为VSC在商城装上插件后就能拎包入住,F5的时候我当场好家伙 于是无脑Install... Installing github.com/nsf/gocode FAILED Installing g ...

  3. P5736 质数筛

    原题连接 一看到这个熟悉的输入,我们就立马反应过来要请出一维数组来记录一下输入的数据.现在数据的存储解决了,紧接着来剖析一下步骤: 输入数据 一个一个的判断是否为质数 筛去合数 输出质数 理清了思路后 ...

  4. 解决linux多网卡线路选择----windows arp绑定

    1.arp -a 查看所有arp状态,有静态和动态 2.临时绑定ip和MACarp -s IP MAC //MAC用-分割 3.使用netsh做永久绑定a) 查看接口序号(Idx):netsh i i ...

  5. 百题计划-4 codeforces 652 div2 D. TediousLee 找规律

    https://codeforces.com/contest/1369/problem/D n<=2e6,所以只要找递推式就可以了,不需要找快速幂 /** */ #include<bits ...

  6. win/ubuntu/centos 安装后台监控工具btop

    之前linux平台进行后台监控一直是简单的看top,但界面太难看而且需要记的缩写太多而且不直观(对于我来说),后面有尝试替换htop,扩展支持了鼠标操作以及直观监控,但是界面还是难看,今天查找了一下发 ...

  7. jjupyter notebook 修改存储位置和修改默认浏览器

    先jupyter notebook --generate-config 找到配置文件位置 打开这里的哪个文件 然后修改即可 1.修改默认打开目录找到 #c.NotebookApp.notebook_d ...

  8. C++ primer笔记 -变量和基本类型

    由于头文件会被包含在多个源文件中,所以不应该含有变量或者函数的定义.但又三个列外: 1.头文件可以定义类 2.值在编译时就已经知道的const对象(const对象默认为定义它的文件的局部变量,即在.c ...

  9. 淘淘商城项目技术点-9:使用FTPClient及FtpUtil工具类将图片上传至ngnix图片服务器

    package com.taotao.controller; import com.taotao.common.utils.FtpUtil; import org.apache.commons.net ...

  10. mysql命令行如何执行sql脚本

    本文介绍在windows操作系统和Linux操作系统中,如何在命令界面模式下执行对应的sql脚本到mysql数据库 Windows操作系统下 mysql -u root -p db1 < E:\ ...