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. Windows10+VS2019从源码编译 Qt5

    参考 Windows10+MSVC(VS2022)从源码编译QT5.12.11 - 知乎 (zhihu.com) qt-labs/vstools ~ qt-labs/vstools (github.c ...

  2. 本地CentOS8 配置ssh免密登录服务器

    准备工作: 1.确认本机sshd的配置文件(需要root权限) $ vi /etc/ssh/sshd_config 找到以下内容,并去掉注释符"#" AuthorizedKeysF ...

  3. Go语言格式化金额为3个一组隔开

    最近在Go语言项目上面遇到了一个金额相关的问题,想更加规范的将金额用逗号隔开3个分为一组,这样显示更专业一点,经过一番努力,找到这个下面这个插件,经过测试发现比较好用,特此分享出来. 第一步先下载一个 ...

  4. JMeter创建上传文件脚本

    环境:Macbook10 ,apache-jmeter-4.0 1. 创建脚本:添加 -> Sampler -> HTTP请求 2.基本配置 3. 设置实现方式,这一步是关键的关键.... ...

  5. ssl自动更新证书

    安装证书 yum install certbot 更新证书之前先开启80 443 端口 自动生成证书certbot certonly --standalone --agree-tos -n -d ww ...

  6. JS基础笔记汇总

    JS基础笔记最全的汇总 javascript介绍以及起源目录1.变量和常量的知识2.基本数据类型3.运算符4.基本数据类型间的转换5.流程控制语句 一.javascript介绍以及起源 js一种直译型 ...

  7. 基于CentOS搭建FTP文件服务实战

    参考教程来自腾讯云开发者实验室:https://cloud.tencent.com/developer/labs/lab/10123 话不多少,进入流程 1. 安装vsftpd 使用 yum 安装 v ...

  8. 如何搭建Redis集群(主从+哨兵)

    一.什么是redis主从复制? 主从复制,是指将一台Redis服务器的数据,复制到其他的Redis服务器.前者称为主节点(master),后者称为从节点(slave),数据的复制是单向的,只能由主节点 ...

  9. SqlServer outer apply(cross apply)

    select * from baiduacg_cookies c cross apply (select top 1 * from product where AccountId=c.AccountI ...

  10. centos7 yum安装配置Lnmp和负载配置

    首先配置防火墙CentOS 7.0默认使用的是firewall作为防火墙1.关闭firewall: systemctl stop firewalld.service #停止firewallsystem ...