【Lightning Linux Series P10】Abacus of Operating System Management——Detailed Explanation of Process

insert image description here

foreword

Hello everyone, welcome to the YY drop Linux series, a warm welcome! The main content of this chapter is aimed at veterans who have been in touch with Linux, and introduces the process from the operating system level:
the main content includes:
insert image description here

Welcome to subscribe to the YY drop Linux column! More dry goods are continuously updated! The following is the portal!

Subscribe to the column reading: YY 's "Linux" series❀❀❀❀❀
【Linux Series-P1】Building a Linux Environment
[Linux Series-P2] Basic knowledge and instructions of Linux
【Linux Series-P3】Linux Permissions
[Linux series-P4] Linux basic tools [yum] [vim]

1. The basic concept of process

  • Textbook concepts: an execution instance of a program, a program being executed, etc.
  • Kernel point of view: Acts as the entity that allocates system resources (CPU time, memory).

2. Describe the process-PCB

  • Process information is placed in a data structure called a process control block, which can be understood as a collection of process attributes.
  • The textbook is called PCB (process control block), and the PCB under the Linux operating system is: task_struct

A type of task_struct-PCB

  • The structure describing the process in Linux is called task_struct.
  • task_struct is a data structure of the Linux kernel that is loaded into RAM (memory) and contains process information.

task_ struct content classification

  • Identifier: Describe the unique identifier of this process, which is used to distinguish other processes.
  • Status: Task status, exit code, exit signal, etc.
  • Priority: Priority relative to other processes.
  • Program Counter: The address of the next instruction in the program to be executed.
  • Memory pointers: including pointers to program code and process-related data, as well as pointers to memory blocks shared with other processes
  • Context data: The data in the registers of the processor when the process is executed [example of suspension of studies, to add pictures of CPU, registers].
  • I/O status information: including displayed I/O requests, I/O devices assigned to the process and a list of files used by the process.
  • Billing information: May include sum of processor time, sum of clocks used, time limits, billing account number, etc.
  • other information

4. "Organizational Process"

  • It can be found in the kernel source code. All processes running in the system are stored in the kernel in the form of task_struct linked list .

5. "View process"

Operation 1: View process information

Process information can be viewed through the /proc system folder

  • For example: To obtain the process information with PID 1, you need to view the /proc/1 folder.

Operation 2: Use user-level tools such as top and ps to obtain process information

  • first create a process
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
int main()
{
    
    
 while(1){
    
    
 sleep(1);
 }
 return 0;
}
  • After filtering with grep pipeline:

insert image description here

Guess you like

Origin blog.csdn.net/YYDsis/article/details/132309774