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

Query the data of the day before the current time interval in MySQL

1. Background In actual projects, we will encount...

Detailed explanation of the solution to forget the password in MySQL 5.7

ENV: [root@centos7 ~]# uname -r 3.10.0-514.el7.x8...

Implementation of docker-compose deployment of zk+kafka+storm cluster

Cluster Deployment Overview 172.22.12.20 172.22.1...

In-depth understanding of the matching logic of Server and Location in Nginx

Server matching logic When Nginx decides which se...

Troubleshooting the cause of 502 bad gateway error on nginx server

The server reports an error 502 when synchronizin...

Detailed steps to install Anaconda on Linux (Ubuntu 18.04)

Anaconda is the most popular python data science ...

Detailed explanation of various loop speed tests in JS that you don’t know

Table of contents Preface 1. for loop 2. while lo...

CentOS8 - bash: garbled characters and solutions

This situation usually occurs because the Chinese...

How to start the spring-boot project using the built-in linux system in win10

1. Install the built-in Linux subsystem of win10 ...

Linux echo text processing command usage and examples

The description of echo in the Linux help documen...

Vue based on Element button permission implementation solution

Background requirements: The ERP system needs to ...

Docker data storage tmpfs mounts detailed explanation

Before reading this article, I hope you have a ba...

select the best presets to create full compatibility with all browsersselect

We know that the properties of the select tag in e...

How to represent various MOUSE shapes

<a href="http://" style="cursor...

Example code for implementing random roll caller in html

After this roll call device starts calling the ro...