Process Switching

1、The set of data that must be loaded into the registers before the process resumes its execution on the CPU is called the hardware context.In Linux, a part of the hardware context of a process is stored in the process descriptor, while the remaining part is saved in the Kernel Mode stack.

2、Process switching occurs only in Kernel Mode.The contents of all registers used by a process in User Mode have already been saved on the Kernel Mode stack before performing process switching.This includes the contents of the ss and esp pair that specifies the User Mode stack pointer address.

3、The 80x86 architecture includes a specific segment type called the Task State Segment(TSS), to store hardware contexts.When an 80x86 CPU switches from User Mode to Kernel Mode, it fetches the address of the Kernel Mode stack from the TSS.

4、Each process descriptor includes a field called thread of type thread_struct, in which the kernel saves the hardware context whenever the process is being switched out.This data structure includes fields for most of the CPU registers, except the general-purpose registers such as eax, ebx, etc, which are stored in the Kernel Mode stack.

Processes,Lightweight Processes, and Threads

Linux uses lightweight processes to offer better support for multithreaded applications.Basically, two lightweight processes may share some resources, like the address space, the open files, and so on.Whenever one of them modifies a shared resource, the other immediately sees the change.

A straightforward way to implement multithreaded applications is to associate a lightweight process with each thread.

In Linux a thread group is basically a set of lightweight processes that implement a multithreaded application and act as a whole with regards to some system calls such as getpid(), kill(), and _exit().

Unix programmers expect threads in the same group to have a common PID.To comply with this standard, Linux makes use of thread groups.The identifier shared by the threads is the PID of the thread group leader, that is, the PID of the first lightweight process in the group;it is stored in the tgid field of the process descriptors.The getpid() system call returns the value of tgid relative to the current process instead of the value of pid, so all the threads of a multithreaded application share the same identifier.Most processes belong to a thread group consisting of a single member; as thread group leaders, they have the tgid field equal to the pid field, thus the getpid() system call works as usual for this kind of process.

《深入理解Linux内核》阅读笔记 --- Chapter 3 Processes的更多相关文章

  1. 深入理解Linux内核 学习笔记(1)

    1.用户和用户组 每个用户是一个或多个用户组的一名成员,组由唯一的用户组标识符(user group ID)标识.每个文件的相关权限也恰好与一个组相对应. root为超级用户, 2.模块 为了达到微内 ...

  2. 深入理解Linux内核 学习笔记(5)

    第五章  定时测量 内核必须显式地与三种时钟打交道:实时时钟(Real Time Clock, RTC).时间标记计数器(Time Stamp Counter, TSC)及可编程间隔定时器( Prog ...

  3. 深入理解Linux内核 学习笔记(4)

    第四章 中断和异常 中断通常被分为同步中断和异步中断,同步中断是当指令执行时由CPU控制单元产生的,之所以称为同步,是因为只有在一条指令终止执行后CPU才会发出中断异步中断是由其他硬件设备依照CPU时 ...

  4. 深入理解Linux内核 学习笔记(3)

    第三章 进程 可以看到很多熟悉的结构体 进程状态: 可运行状态(TASK_ RUNNING) 进程要么在CPU上执行,要么准备执行. 可巾断的等待状态(TASK_ INTERRUPTIBLE) 进程被 ...

  5. 深入理解Linux内核 学习笔记(2)

    第二章 :内存寻址 略.基本同计算机组成原理中的讲述 内核代码和数据结构会存储在一个保留的页框中. 常规Linux安装在RAM物理地址0x00100000开始的地方.因为:页框0是由BIOS使用,存放 ...

  6. 深入理解Linux内核 学习笔记(8)

    第八章 系统调用 API定义了一个给定的服务:系统调用是通过软中断向内核发出一个明确的请求. API可能不调用系统调用,也可能调用多个系统调用. Linux系统调用必须通过执行int 0x80,系统调 ...

  7. 《深入理解Linux内核》 读书笔记

    深入理解Linux内核 读书笔记 一.概论 操作系统基本概念 多用户系统 允许多个用户登录系统,不同用户之间的有私有的空间 用户和组 每个用于属于一个组,组的权限和其他人的权限,和拥有者的权限不一样. ...

  8. 读书笔记之Linux系统编程与深入理解Linux内核

    前言 本人再看深入理解Linux内核的时候发现比较难懂,看了Linux系统编程一说后,觉得Linux系统编程还是简单易懂些,并且两本书都是讲Linux比较底层的东西,只不过侧重点不同,本文就以Linu ...

  9. 【读书笔记::深入理解linux内核】内存寻址【转】

    转自:http://www.cnblogs.com/likeyiyy/p/3837272.html 我对linux高端内存的错误理解都是从这篇文章得来的,这篇文章里讲的 物理地址 = 逻辑地址 – 0 ...

随机推荐

  1. 13个实用的Apache Rewrite重写规则

    1.去掉域名中的www标记 复制代码 代码如下: RewriteCond %{HTTP_HOST} !^jb51\.net$ [NC]RewriteRule .? http://jb51.net%{R ...

  2. Selenium操作之滚动条

    在用Selenium做UI自动化时,经常会遇到有些元素找不到之类的问题,但是自己的代码并没有错,元素就是找不到,这是为什么呢?原因很简单,由于页面内容较多,有些内容需要下拉滚动条才会显示,这里介绍一种 ...

  3. strncmp----c++库函数

    某天,蒜头君和花椰妹在公园里散步,走着走着,我的天!他们各自都捡到了一串漂亮的字符串,然而蒜头君好奇心比较重,他想知道自己的字符串在花椰妹的字符串中出现了多少次,例如花椰妹的字符串为abababa,蒜 ...

  4. Unknown module(s) in QT: xlsx解决方法

    解决方法在此: https://github.com/dbzhang800/QtXlsxWriter Documentation: http://qtxlsx.debao.me QtXlsx is a ...

  5. git三种模式及常用命令

    Git的三种重要模式,分别是已提交.已修改.已暂存. 已提交(committed):表示数据文件已经顺利提交到Git数据库中. 已修改(modified):表示数据文件已经被修改,但未被保存到Git数 ...

  6. HTML基本元素的运用

    段落相关标签<p><br><hr> 格式化相关标签<small><sub><sup><pre> 列表相关标签< ...

  7. Mysql8.0.16 only_full_group_by

    [1]Mysql8.0.16 关于only_full_group_by问题 应公司业务的需求,安装了Mysql8.0.16版本,原来在Mysql5.6版本执行无恙的SQL语句: SELECT prod ...

  8. spark(1.1) mllib 源码分析(三)-朴素贝叶斯

    原创文章,转载请注明: 转载自http://www.cnblogs.com/tovin/p/4042467.html 本文主要以mllib 1.1版本为基础,分析朴素贝叶斯的基本原理与源码 一.基本原 ...

  9. 一个事半功倍的c#方法 动态注册按钮事件

    前几天在网上看见一个制作计算器的c#程序,其中有一个动态注册按钮事件,觉的很有用.于是实际操作了一哈, 确实比较好. 言归正传,下面就来讲讲怎样动态注册按钮事件. 首先,我们需要设置变量来获取点击一个 ...

  10. jquery取iframe中元素

    采取方法: $("#iframe_path").contents().find(".select_path_hide").val(); DOM方法:父窗口操作I ...