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. JUC续

    设计模式,保护性暂停.解耦 生产者消费者模式 park.unpark 线程状态转换 锁超时 锁超时可以解决哲学家就餐问题 公平锁 条件变量 线程控制顺序

  2. 报错解决OSError: /lib64/libm.so.6: version `GLIBC_2.27' not found

    使用pyg报错如下: 1 Traceback (most recent call last): 2 File "main.py", line 18, in <module&g ...

  3. GoLang之ACM控制台输入输出

    转自:https://blog.csdn.net/weixin_52690231/article/details/125436414

  4. 用JMeter对MySQL数据库进行压测

    转载链接:https://www.cnblogs.com/Jadie/p/8056541.html 参考链接:https://blog.csdn.net/qq_35389417/article/det ...

  5. 【36oj】 画圣诞树

    原题 圣诞节要到了,不少商家在宣传板上绘制了圣诞树的图案,如图所示.一棵圣诞树由A和B两部分组成: A是由n(n≥)个呈三角形的字符矩阵构成的,每个字符矩阵由三个参数ai.bi.ci唯一确定.Ai表示 ...

  6. wtform的用法

    1.登录用法from flask import Flask, render_template, request, redirectfrom wtforms import Form,validators ...

  7. idea插件Tranlation配置有道搜索引擎

    idea配置有道翻译引擎 一.更换翻译引擎原因 由于Google在2022年9月末宣布关闭GoogleTranslate在中国的服务,原本在chrome浏览器和idea上使用的google翻译引擎也不 ...

  8. 【git】3.2git分支-分支的新建与合并

    资料来源 (1) https://git-scm.com/book/zh/v2/Git-%E5%88%86%E6%94%AF-%E5%88%86%E6%94%AF%E7%9A%84%E6%96%B0% ...

  9. Impala 学习笔记

    VALUES Statement | 6.3.x | Cloudera Documentation SELECT now() as date_DES UNION ALL SELECT trunc(no ...

  10. windows下C#读文件遇到一个路径的天坑

    在win下面准备了一个文件,右键属性然后"安全"复制完整的文件路径, 放到C#代码(vs中编写)中来读取,竟然死活异常: System.IO.IOException HResult ...