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.



  • chenghuaying
  • chenghuaying
  • 2014年03月31日 16:47
  • 4511


概述:软件开发流程(Software development process)即软件设计思路和方法的一般过程,包括设计软件的功能和实现的算法和方法、软件的总体结构设计和模块设计、编程和调试、程序联调和...
  • u010963246
  • u010963246
  • 2015年07月08日 12:43
  • 2379


  • zhou307
  • zhou307
  • 2016年05月05日 12:28
  • 1240

【APUE 学习笔记】4: Unix Process Control 进程控制

  • elloop
  • elloop
  • 2016年10月11日 23:27
  • 306

学习笔记之深入浅出MFC 第7章 进程与线程(Process and Thread)

os/2、Windows NT以及Windows 9x都支持多线程,这给程序员带来了很大的便利。然而,在使用多线程的时候,必须要处理好各线程之间的关系,否则会带来很多麻烦。 进程(process)表示...
  • walkman_lfq
  • walkman_lfq
  • 2016年04月22日 16:51
  • 688

nginx 源码学习笔记(十七)—— ngx_worker_process_cycle子进程执行

上一节主要讲解主进程如何开启子进程,并且讲解了主进程做的一些操作,这一节主要学习子进程处理函数ngx_worker_process_cycle src/os/unix/ngx_process_cyc...
  • lengzijian
  • lengzijian
  • 2012年05月22日 16:08
  • 5296

nginx 源码学习笔记(十五)—— ngx_master_process_cycle 多进程(一)

  • huangyimo
  • huangyimo
  • 2015年12月01日 20:14
  • 281

nginx 源码学习笔记(二十一)—— event 模块(二) ——事件驱动核心ngx_process_events_and_timers

首先继续回忆下,之前子线程执行操作里面有一个未涉及的内容ngx_process_events_and_timers,今天我们就来研究下这个函数。 本篇文章来自于:http://blog.csdn.n...
  • lengzijian
  • lengzijian
  • 2012年05月25日 16:25
  • 9368

Contiki 学习笔记:process_run 解析

process_run用于处理系统所有needspoll标记为1的进程及处理事件队列的下一个事件。本文深入原码,详细分析,也包括do_poll和do_event函数。 一、运行process...
  • broadCE
  • broadCE
  • 2015年05月18日 11:37
  • 1086

《APUE》Chapter 9 Process relationships (学习笔记加上自己的代码)

Process  Relationships Terminal  Logins Unix 是1971年开始的吧,但是这个terminal login的机制最起码30年没变过,嘿嘿。。。 ...
  • u011368821
  • u011368821
  • 2014年03月30日 00:03
  • 1909
您举报文章:linux 学习笔记之 Process Control