4 Some basic concepts of Linux system


Preface (including table of contents)


program Binary files placed on disk when not running
process After starting the running program, the data is in the memory, occupying system resources such as CPU
Use the coffee machine in the picture below as an analogy
Concurrent In order to allow everyone to drink coffee within a period of time, this time period is divided into many small segments. The time for one person to pick up coffee is a short period. People take turns to pick up the coffee. At every moment, there is only One person was receiving coffee, but within a period of time, everyone received coffee
parallel Two coffee machines work at the same time, both sides can receive coffee at the same time

Insert picture description here
The way the CPU works is similar to concurrency. Take a look at the task manager. The number of running processes may be tens of thousands. It is impossible to wait for the execution of one by one. Change the next process to get the CPU for execution, so you can't do it. Then, the computer is playing music while browsing and looking up the data. Instead, the 1s is split, and the 1GHz (1x10 3 x10 3 x10 3 ) processor has 1 billion cycles, allowing each process to execute alternately. This executes several cycles, It is executed for a few cycles, because the speed is too fast, and the user can't see that it is alternately executed, and it feels like they are running together.

For the state that the process can be in, see the following diagram:
Insert picture description here

Linux virtual address space
Under the 32-bit CPU architecture, there are currently 36 address lines that can be used, and the maximum physical address that can be used is 2 36 B, that is, 64 GB, and the available address space is 4 GB. Each process running under 32-bit Linux , The operating system will allocate a 0~4G virtual address space for it (see the figure below).
Insert picture description here

Under the 64-bit CPU architecture, the currently supported address lines are 46, and the maximum supported physical address is 2 46 B, that is, 64 TB, and the available address space is 64 TB. The distribution of the 64-bit virtual address space is similar to that of 32-bit, but the middle is left blank. , Only use both ends.

Insert picture description here

In addition, the previous article mentioned that it 文件描述符(表)is located PCB(进程控制块), and the PCB is in the Linux内核middle. The implementation of the PCB is in the task_structstructure, and the interior is very complicated. Here is a brief description of what you can often encounter.

  • Process ID: Each process in the system has a unique ID, which is represented by pid_t in C language.
  • The status of the process: ready, running, suspended, stopped...
  • Some CPU registers that need to be saved and restored during process switching
  • Information describing the virtual address space
  • Information describing the control terminal
  • Current working directory
  • umask mask
  • The file descriptor table contains many pointers to the file structure
  • Signal-related information
  • User ID and Group ID
  • Session and process group
  • The upper limit of the resources that the process can use
ulimit -a

Guess you like

Origin blog.csdn.net/weixin_45579994/article/details/112760392