Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to understand the process Management Mechanism of Linux system

2025-01-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "how to understand the process management mechanism of Linux system". In daily operation, I believe many people have doubts about how to understand the process management mechanism of Linux system. Xiaobian consulted all kinds of information and sorted out simple and easy to use operation methods. I hope to help you answer the doubts about "how to understand the process management mechanism of Linux system"! Next, please follow the small series to learn together!

I. Concept and classification of processes

1. Concept of process

Linux is a multi-user multitasking operating system.

Multiple users means that multiple users can use the same Linux system at the same time.

Multitasking refers to multiple tasks that can be performed simultaneously under Linux. In more detail, Linux uses a time-sharing management method. All tasks are placed in a queue. The operating system allocates appropriate time slices for each task according to the priority of each task. Each time slice is very short. Users simply do not feel that multiple tasks are running, so that all tasks share system resources together. This is the concept of multitasking.

The above is the case of a single-CPU multitasking operating system. In this environment, although the system can run multiple tasks, at a certain point in time, the CPU can only execute one process. In a multi-CPU multitasking operating system, because there are multiple CPUs, there can be multiple processes running at a certain point in time.

The basic definition of a process is that it is an independent program running in its own virtual address space, and from the operating system perspective, everything that runs on the system can be called a process.

Note that the relationship between programs and processes can be many-to-many!

2. Classification of processes

According to the function of the process and the classification of the program running, the process can be divided into two main categories:

l) System process: it can perform management work such as memory resource allocation and process switching; moreover, the operation of the process is not subject to user intervention, even the root user cannot interfere with the operation of the system process.

2)User process: A process that results from the execution of user programs, application programs, or system programs outside the kernel and can run or shut down under user control.

For user processes, they can be divided into interactive processes, batch processes and daemon processes.

3)Interactive process: A process initiated by a shell terminal that interacts with the user during execution and can run in the foreground or background.

4)Batch process: This process is a collection of processes responsible for starting other processes in sequence.

5)Daemons: daemons are always-running processes that are often started at linux startup and terminated at system shutdown. They are independent of the control terminal and periodically perform certain tasks or wait for certain events to occur. The httpd process, for example, is always running, waiting for access from users. There is also the often used crond process, which is similar to windows scheduled tasks and can periodically perform certain tasks set by the user.

3. Properties of the process

(1) Several states of the process

(2) Relationship between processes

In Linux systems, process IDs (represented by PID) are unique identifiers that distinguish different processes, and their size is limited, with a maximum ID of 32768. UID and GID represent the user and user group that started the process, respectively. All processes are descendants of the init process with PID 1. The kernel starts the init process at the last stage of system startup, so this process is the parent of all processes under Linux, denoted by PPID. So if the init process is killed, that means all processes are killed, and the system is restarted or shut down.

Example: httpd process information output by ps command:

Relative to the parent process, there are child processes. Generally, each process must have a parent process. The relationship between the parent process and the child process is management and managed. When the parent process stops, the child process also disappears, but the child process closes, and the parent process does not necessarily terminate.

If the parent process exits before the child process exits, then all child processes become an orphan process. If there is no corresponding processing mechanism, these orphan processes will always be in a dead state and resources cannot be released. At this time, the system defaults to the init process as their parent process.

II. Process management commands

Under Linux, there are many commands for monitoring and managing processes. Below we introduce the four most commonly used commands, ps, top, pstree and lsof, to effectively monitor and manage various processes under Linux.

(1)Monitoring System Progress with ps Command

Ps is the most commonly used process monitoring command under linux, focusing on how to use ps instructions to monitor and manage system processes.

Examples:

Here is the output from the apache process

UID is the user ID, PID is the process ID, PPID represents the parent process, STIME represents the start time of the process, TTY represents the terminal console to which the process belongs, TIME represents the accumulated CPU time used after the process starts, and CMD represents the command being executed. And root's PID is 1, which is Init's ID.

Another way to view the correspondence between child processes and parent processes:

where %CPU represents the percentage of CPU consumed by the process, %MEM represents the percentage of memory consumed by the process, VSZ represents the virtual size of the process, and RSS represents the actual memory (resident set) size of the process in pages.

STAT represents the state of a process. There are many states of a process: "R" represents a running process,"S" represents a dormant process,"Z" represents a dead process, and "

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report