zoukankan      html  css  js  c++  java
  • 《深入理解Linux内核》阅读笔记 --- Chapter 3 Processes

    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.

  • 相关阅读:
    VC++使用socket进行TCP、UDP通信实例总结
    [Android Pro] 调用系统相机和图库,裁剪图片
    [Android Pro] 查看 keystore文件的签名信息 和 检查apk文件中的签名信息
    [Android 新特性] 谷歌发布Android Studio开发工具1.0正式版(组图) 2014-12-09 09:35:40
    [Android 新特性] 有史来最大改变 Android 5.0十大新特性
    [Android Pro] service中显示一个dialog 或者通过windowmanage显示view
    [Android Pro] 通过Android trace文件分析死锁ANR
    [Android Memory] Android 的 StrictMode
    [Android Memory] Android性能测试小工具Emmagee
    [Android Memory] Android内存管理、监测剖析
  • 原文地址:https://www.cnblogs.com/YaoDD/p/6306389.html
Copyright © 2011-2022 走看看