Detailed explanation of process management in Linux system

Detailed explanation of process management in Linux system

1. The concept of process and thread

Source: Baidu Encyclopedia:

A process is an operation of a program in a computer on a certain data set. It is the basic unit for resource allocation and scheduling in the system and the foundation of the operating system structure. In contemporary thread-oriented computer architectures, processes are containers for threads. A program is a description of instructions, data and their organizational form, and a process is the entity of a program. It is an operation of a program in a computer on a certain data set. It is the basic unit for resource allocation and scheduling of the system and the foundation of the operating system structure. A program is a description of instructions, data and their organizational form, and a process is the entity of a program.

A thread is the smallest unit that an operating system can schedule operations on. It is contained within the process and is the actual operating unit of the process. A thread refers to a single sequential control flow in a process. Multiple threads can run concurrently in a process, and each thread executes different tasks in parallel.

2. What is process management?

What exactly is a process?

A process is a program or command being executed. Each process is a running entity, has its own address space, and occupies certain system resources.

So what is a program?
A program is a collection of codes written by humans using a computer language to achieve a specific goal or solve a specific problem.

Let's put it another way:

A program is a collection of executable codes written by humans in a computer language that can achieve certain functions. A process is a program that is currently being executed. When a program is executed, the permissions and attributes of the executor, as well as the program code, are loaded into memory. The operating system assigns an ID number to the process, which we call PID (Process ID).

3. The role of process management

Determine the health status of the server: The main job of the operation and maintenance engineer is to ensure the safe and stable operation of the server. The ideal situation is that when a problem occurs on the server, human intervention can solve the problem before it causes the server to crash or stop service. The main task of process management is to determine whether the server is currently running healthily and whether human intervention is required. If the server's CPU usage and memory usage are too high, human intervention is required to solve the problem.

View all processes in the system: We need to view all running processes in the system. Through these processes, we can determine which services are running in the system and whether there are any illegal services running.

Killing a process: This is the least commonly used method of process management. When I need to stop a service, I will stop it by properly shutting down the command (for example, apache service can be shut down through service httpd stop ). Only when the correct means of terminating the process fail, will you consider using the kill command to kill the process (you are not a killer, don't use kill to terminate all processes, otherwise it will easily cause the server to crash)

4. Several states of Linux process

D : A sleep state that cannot be awakened, usually used in I/O situations.

R : The process is running.

S : The process is in sleep mode and can be awakened.

T : Stop state, which may be paused in the background or the process is in debugging state.

W : Memory interaction state (invalid starting from 2.6 kernel).

X : Dead process (should not appear).

Z : zombie process. The process has terminated, but parts of it are still in memory.

< : High priority (the following status appears in BSD format).

N : Low priority.

L : Locked into memory.

s : Include subprocesses.

l : Multithreaded (lowercase L).

+ : In the background.

5. The relationship between processes and threads

(1) Relationship between threads and processes

For example, the computer is running 200 processes at the same time:

Concept of thread and process: Each process contains at least one thread, and these threads are sharing the resource space of the process. When the thread changes, it will only cause the CPU execution process to change, and will not change the resources owned by the process. Similarly, a program contains at least one process. The smallest unit for executing operations in a process, and also the basic unit for executing processor scheduling: Each process has its own address space and resources such as memory, I/O, and CPU. Threads in the same process share the address space of the process. Then, can they use the address space of other processes? Obviously, this is not allowed. Due to the independence of processes, when a process crashes, it will not affect other processes in protected mode. The basic unit of resource allocation, the basic unit of operation scheduling, and the unit of concurrent execution in the system.

Comparison of the two scheduling in the same process, thread switching will not cause process switching.
When a thread of one process switches to a process of another thread, a process switch is caused. Concurrency Processes can be executed concurrently, and threads within a process can also be executed concurrently. Owned resources Generally speaking, a thread does not own its own resources, but it can access the resources in its own process. For example, files opened by a process can be shared by other threads in the process.

(2) Summary

Let's briefly summarize:

Process: refers to an application running in the system. Once a program is running, it becomes a process. A process is the smallest unit of resource allocation. Thread: The basic unit for allocating processor time resources by the system, or a unit execution flow that executes independently within a process. A thread is the smallest unit of program execution.

This is the end of this article about the detailed explanation of process management in Linux system. For more relevant Linux process management content, please search for previous articles on 123WORDPRESS.COM or continue to browse the related articles below. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Linux operation and maintenance basic process management real-time monitoring and control
  • Linux operation and maintenance basic process management and environment composition analysis
  • Linux process management tool supervisor installation and configuration tutorial

<<:  Experience sharing by a front-end supervisor with 7 years of practical experience

>>:  This article tells you how to use event delegation to implement JavaScript message board function

Recommend

Common methods and problems of Docker cleaning

If you use docker for large-scale development but...

How to submit a pure HTML page, pass parameters, and verify identity

Since the project requires a questionnaire, but th...

Javascript uses the integrity attribute for security verification

Table of contents 1. Import files using script ta...

Method to detect whether ip and port are connectable

Windows cmd telnet format: telnet ip port case: t...

Use pure CSS to achieve switch effect

First is the idea We use the <input type="...

Flex layout realizes the layout mode of upper and lower fixed and middle sliding

This article mainly introduces the layout method ...

How to modify the root password of mysql under Linux

Preface The service has been deployed on MySQL fo...

Detailed explanation of nginx anti-hotlink and anti-crawler configuration

Create a new configuration file (for example, go ...

Html Select option How to make the default selection

Adding the attribute selected = "selected&quo...

jQuery plugin to implement stacked menu

A jQuery plugin every day - stacked menu, for you...

Summary of 6 Linux log viewing methods

As a backend programmer, you deal with Linux in m...

Pure CSS code to achieve drag effect

Table of contents 1. Drag effect example 2. CSS I...

Graphic tutorial for installing MySQL 5.6.35 on Windows 10 64-bit

1. Download MySQL Community Server 5.6.35 Downloa...

JavaScript uses canvas to draw coordinates and lines

This article shares the specific code of using ca...

Detailed explanation of Vue configuration request multiple server solutions

1. Solution 1.1 Describing the interface context-...