linux 学习笔记之 Process Control

原创 2007年10月09日 06:35:00
  • Process Identifiers

Every process has unique process ID, a non-negative integer. Process ID 0 is swapper. Process ID 1 is usually the init process and is invoked by the kernel at the end of the bootstrap procedure. The init process never dies. It is a normal user process, not a system process within the kernel, like the swapper, although it does run with super user privileges.

  • Fork Function
    pid_t fork(void)

A technique called copy-on-write (COW) is used. These regions are shared by the parent and child and have their protection changed by the kernel to read-only. If either process tries to modify these regions, the kernel then makes a copy of that piece of memory only, typically a “page” in a virtual memory system.

The parent and child share a file table entry for every open descriptor. It is import that the parent and child share the same of file offset.

  • Child process inherited from parent process:
  1. Real user ID, real group ID, effective user ID, effective group ID
  2. Supplementary group ID
  3. Process group ID
  4. Session ID
  5. Controlling terminal
  6. The set-user-ID and set-group-ID flags
  7. Current working directory
  8. Root directory
  9. File mode creation mask
  10. Signal mask and dispositions
  11. The close-on exec flag from any open file descriptors
  12. Environment
  13. Attached shared memory segments
  14. Memory mappings
  15. Resource limits
  • The differences between child and parent are:
  1. The return value from fork
  2. The process IDs are different
  3. The two processes have different parent process IDs
  4. The child’s tms values are set to 0
  5. File lock set by the parent are not inherited by the child
  6. Pending alarms are cleared for the child
  7. The set of pending signals for the child is set to the empty set
  • vfork Function

The vfork function is intended to create a new process when the purpose of the new process is to exec a new program. The vfork function creates the new process, just like fork, without copying the address space of the parent into the child, as the child will reference that address space; the child simply call exec(or exit) right after the vfork. Instead, while the child is running and until it calls either exec or exit, the child runs in the address space of the parent.

Another difference between the two functions is that vfork guarantees that the child runs first, until the child calls exec or exit.

What happens if the parent terminates before the child? The answer is that the init process becomes the parent process of any process whose parent terminates. We say that the process has been inherited by init.

  • Change User IDs and Group IDs
    int setuid(uid_t uid);
    int setgid(gid_t gid);

Below table show ways to change the three user IDs:




set-user-ID bit off

set-user-ID bit on

super user

unprivileged user

real user ID

effective user ID


saved set-user-ID




copied form effective user ID


set from user ID of grogram file

copied from effective user ID

set to uid

set to uid


set to uid


set to uid



  • User Identification
    char * getlogin(void)

The getlogin function provides a way to fetch that login name. This function cal fail if the process is not attached to a terminal that a user longed in to. We normally call these processes daemons.


gitlab搭建提示inet_interfacesJob for postfix.service failed because the control process exited with erro

Job for postfix.service failed because the control process exited with error code. See "systemctl st...
  • u013697959
  • u013697959
  • 2017年09月20日 15:30
  • 544

Job for postfix.service failed. See 'systemctl status postfix.service' and 'journalctl -xn' for deta

安装gitlab的过程 启动postfix服务 enable成功,start失败 # systemctl start postfix Job for postfix.service failed. ...
  • shiyuan1551
  • shiyuan1551
  • 2016年11月03日 17:31
  • 1792

双语阅读笔记 - 操作系统 - Process Control Block

It is important to realize that only one process can be running on any processor at any instant. 要记住...
  • kenden23
  • kenden23
  • 2013年10月26日 15:42
  • 1840

关于nginx的Job for nginx.service failed because the control process exited with error code.错误

执行 service nginx start或者restart命令出现下面错误 [root@localhost ~]# service nginx restart Job for nginx.ser...
  • jxncwwh
  • jxncwwh
  • 2017年07月05日 17:33
  • 8297


  • u013697959
  • u013697959
  • 2018年01月17日 10:32
  • 121

Linux搭建迅搜( Xunsearch )

运行下面指令下载解压安装包 wget tar -xjf xunsear...
  • u013697959
  • u013697959
  • 2017年10月08日 16:07
  • 303

解决Job for docker.service failed because the control process exited with error code. See "systemctl s

在ubuntu16.04下安装安装docker docker daemon启不起来,报如下错误: Job for docker.service failed because the control ...
  • RonnyJiang
  • RonnyJiang
  • 2017年05月23日 13:20
  • 4752

Job for tomcat.service failed because the control process exited with error code 解决办法:

这个问题是在 《 Linux下Tomcat8.5安装与环境配置 》 时遇到的; 错误信息如下: Job for tomcat.service failed because the control p...
  • Hello_World_QWP
  • Hello_World_QWP
  • 2017年12月22日 10:42
  • 869

Job Control之后续实验(二)

题目一: 设计一段程序,设置子进程的process group id,使其子进程成为该group leader并考虑竞态的发生。 [root@localhost ~]# vim 9_1...
  • LoveStackover
  • LoveStackover
  • 2018年02月06日 21:26
  • 585
您举报文章:linux 学习笔记之 Process Control