linux内核设计与实现读书笔记 第三章

进程管理

对于进程的两种虚拟化方式

On modern operating systems, processes provide two virtualizations: a virtualized processor and virtual memory.

如何生成一个新的进程

A process begins its life when, not surprisingly, it is created. In Linux, this occurs by means of the fork() system call, which creates a new process by duplicating an existing one.

Often, immediately after a fork it is desirable to execute a new, different program.The exec() family of function calls creates a new address space and loads a new program into it.

进程描述符(task_struct)

The kernel stores the list of processes in a circular doubly linked list called the task list. Each element in the task list is a process descriptor of the type struct task_struct, which is defined in <linux/sched.h>.

进程描述符包含的内容

The process descriptor contains the data that describes the executing program—open files, the process’s address space, pending signals, the process’s state, and much more

进程描述符在vm中的位置

进程所处的五种状态

TASK_RUNNING

The process is runnable; it is either currently running or on a run- queue waiting to run

TASK_INTERRUPTIBLE

The process is sleeping (that is, it is blocked), waiting for some condition to exist.The process also awakes prematurely and becomes runnable if it receives a signal.

TASK_UNINTERRUPTIBLE

This state is identical to TASK_INTERRUPTIBLE except that it does not wake up and become runnable if it receives a signal.

__TASK_TRACED

The process is being traced by another process, such as a debug-

ger, via ptrace

__TASK_STOPPED

Process execution has stopped; the task is not running nor is it eligible to run.

进程状态流转图

进程上下文(process context)

When a program executes a system call (see Chapter 5,“System Calls”) or triggers an exception, it enters kernel-space.At this point, the kernel is said to be “executing on behalf of the process” and is in process context.

System calls and exception handlers are well-defined interfaces into the kernel.A process can begin executing in kernel-space only through one of these interfaces—all access to the kernel is through these interfaces.

进程家族

All processes are descendants of the init process, whose PID is one.

进程创建

Unix takes the unusual approach of separating these steps into two distinct functions: fork() and exec(). The first, fork(), creates a child process that is a copy of the current task. It differs from the parent only in its PID (which is unique), its PPID (parent’s PID, which is set to the original process), and certain resources and statistics, such as pending signals, which are not inherited.The second function,exec(), loads a new executable into the address space and begins executing it.

linux中的线程实现

Threads are a popular modern programming abstraction.They provide multiple threads of execution within the same program in a shared memory address space.They can also share open files and other resources.

To these other operating systems, threads are an abstraction to provide a lighter, quicker execution unit than the heavy process.To Linux, threads are simply a manner of sharing resources between processes (which are already quite lightweight).

内核线程(kernel thread)

kernel threads do not have an address space

They operate only in kernel-space and do not context switch into user-space.

Linux delegates several tasks to kernel threads, most notably the flush tasks and the ksoftirqd task.(功能)

Kernel threads are created on system boot by other kernel threads. Indeed, a kernel thread can be created only by another kernel thread

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值