Linux process management and function

Whether it is a Linux system administrator or an ordinary user, it is a daily routine to monitor the operation of system processes and terminate some out-of-control processes in due course. Compared with Linux system, process management in Windows is more intuitive, it mainly uses "task manager" for process management.

Usually, there are three main purposes of using the "Task Manager":
use the "Application" and "Process" tabs to see which programs and processes are running in the system;
use the "Performance" and "User" tabs to judge the health status of the server;
forcefully terminate tasks and processes in the "Applications" and "Process" tabs;

Although Linux uses commands for process management, the main purpose of process management is the same, that is, to view the programs and processes running in the system, to judge the health status of the server, and to forcibly terminate unnecessary processes.

So, what exactly is a process? What is the connection between it and what we usually call "program"?
What are processes and programs
? A process is a program or command being executed. Each process is a running entity with its own address space and occupies certain system resources. A program is a collection of codes written by humans using computer language to achieve specific goals or solve specific problems.

It's hard to understand in this way, so let's put it another way. A program is a collection of codes that are written by humans using a computer language, can achieve certain functions, and can be executed. A process is a program that is being executed. When the program is executed, the permissions and attributes of the executor, as well as the code of the program will be loaded into the memory, and the operating system assigns an ID to the process, called PID (process ID).

That is to say, in the operating system, all executable programs and commands will generate processes. It's just that some programs and commands are very simple, such as ls command, touch command, etc. They will end after execution, and the corresponding process will also end, so it is difficult for us to capture these processes. However, there are still some programs and commands, such as the httpd process, which will always reside in the system after startup. We call such processes permanent memory processes.

Some processes will generate some new processes, we call these processes child processes, and the process itself is called the parent process. For example, we must normally log in to the shell environment to execute system commands, and the standard shell of Linux is bash. We execute the ls command in bash, then bash is the parent process, and the ls command is a process generated in the bash process, so the ls process is the child process of the bash process. That is to say, the child process is generated by relying on the parent process. If the parent process does not exist, the child process does not exist either.
The role of process management
In the process of using the Windows system, the task manager is used to a large extent to forcibly close "unresponsive" software, that is, to kill the process. Indeed, this is the most common method used by many people who use process management tools or process management commands. However, killing a process (forcibly terminating a process) is only the least commonly used method in process management work, because each process has its own correct method of ending, and killing a process is a backup method in case the normal method has failed.

So, what should process management do? In my opinion, process management mainly has the following three functions.

  1. Judging 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. Ideally, when there is a problem with the server, but it has not caused the server to go down or stop the service, human intervention solves the problem.

The main job of process management is to judge whether the server is currently running healthy or not, and whether human intervention is required. If the CPU usage and memory usage of the server are too high, human intervention is required to solve the problem. Here comes another problem, we found that the CPU or memory usage of the server is high, how to intervene? Is it to directly terminate the high-load process?

Of course not, you should judge whether this process is a normal process. If it is a normal process, it means that your server can no longer meet the application requirements, and you need better hardware or build a cluster;

Of course, if the number of servers is small, we can monitor and intervene manually through process management commands, but if the number of servers is large, manual monitoring becomes very difficult. At this time, we need corresponding monitoring services, such as cacti or nagios. In short, the most important task in process management is to judge the health status of the server. The ideal state is to solve the problem before the server goes down, so as to avoid the server downtime.
2) View all the processes in the system
We need to view all the running processes in the system, through these processes we can determine which services are running in the system and whether there are illegal services running.
3) Killing the process
This is the least common means of process management. When the service needs to be stopped, the service will be stopped through the correct shutdown command (for example, the apache service can be stopped by the service httpd stop command). Killing a process with the kill command is only considered if the means of properly terminating the process fails.

In fact, the process management is very similar to the task manager in Windows, but when you use the task manager, it is to kill the process, not to judge the health status of the server.

Guess you like

Origin blog.csdn.net/D0126_/article/details/131471034