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

What are the commonly used process management commands in Linux

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly explains "what are the commonly used process management commands in Linux", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let Xiaobian take you to learn "What are the commonly used process management commands in Linux"!

1.ps

'ps' is the most basic command in Linux to navigate through processes in the system. Can list the processes running in the system, including process numbers, commands, CPU usage, memory usage, etc. The following options can be used to get more useful information.

ps -a -List all running/active processes ps -ef| grep -List processes required ps -aux -Display process information, including processes without terminals (x) and for users (u): such as USER, PID, %CPU, %MEM, etc. 2.pstree

In linux, every process is created by its parent. This command visually displays processes, showing relationships between processes by displaying a tree diagram of the processes. If a pid is specified, then the root of the tree is that pid, otherwise it will be init (pid: 1).

3.top

'top' is a more useful command to monitor the resources used by different processes in the system. It provides real-time system status information. Data showing the process includes PID, process ownership, priority, %CPU, %memory, etc. These displays can be used to indicate resource usage.

4.htop

Htop is similar to top, but htop is an interactive text-mode progress viewer. It graphically displays the CPU and memory usage and swap usage of each process through text. Use the up and down cursor keys to select a process, F7 and F8 to change priority, and F9 to kill a process. Htop is not installed by default, so additional installation is required.

5.nice

With the help of the nice command, users can set and change process priorities. Raising the priority of a process causes the kernel to allocate more CPU time slices to that process. By default, processes start with priority 0. The process priority can be viewed in the NI (nice value) column displayed by the top command.

Process priority values range from-20 to 19. The lower the value, the higher the priority.

nice - Start a program with a given priority value

In the above command example, you can see that the 'top' command gets a priority of-3.

6.renice

The renice command is similar to the nice command. Use this command to change the priority of a running process. Note that users can only change the priority of their own processes.

renice -n -p -Change the priority of the specified process

Process 3806, which started with a priority of 0, has now become 4.

renice -u -g -Change process priority by specifying users and groups

In the example above, all processes whose user is 'mint' have priority values of '-3'.

7.kill

This command is used to send a signal to end the process. If a process does not respond to the kill command, this may require a forced kill, using the-9 argument. Note that you must be careful when using force kill, because the process does not have the opportunity to clean up the site, and the write file may not be completed. killall is useful if we don't know that PID of the proces or if we intend to kill the process by name.

kill -9 kill all-9 -Kill all processes with the same name

If you use kill, you need to know the process ID. pkill is a similar command but uses pattern matching such as process name, process owner, etc.

pkill8.ulimit

This command controls the allocation of system resources to shells and processes. It is most useful for system administrators to manage heavily used and performance problem systems. Limiting resource size ensures that important processes continue to run and that other processes do not consume too many resources.

ulimit -a -Displays resource limits associated with the current user

-f : Maximum file size

-v : Maximum virtual memory size (KB)

-n : Increase the maximum number of file descriptors

-H : Change and report hard limits

-S : Change and report soft limits

Visit the ulimit man page for more options.

9.w

w Provides information about the currently logged in user and the processes they are executing. The display header contains information such as the current time, system run time, total number of logged in users, and the number of Load Balancer in the past 1, 5, and 15 minutes.

Based on this user information, users should be careful when terminating processes that do not belong to them.

Who is a similar command, providing a list of currently logged in users, system startup time, run level, etc.

whoami command outputs the current user ID

10.pgrep

pgrep means "process number global regular matching output." This command scans the currently running process and lists the matching results to standard output according to the command matching criteria. Useful for retrieving process numbers by name.

pgrep -u mint sh

This command will display a process ID with user 'mint' and process name 'sh'.

11.fg , bg

Sometimes, commands take a long time to execute. In this case, we can use the 'bg' command to put the task in the background, and use 'fg' to bring it to the foreground.

We can launch a program in the background with '&':

find . -name *iso > /tmp/res.txt &

A running program can also be placed in the background using the CTRL+Z and bg commands.

find . -name *iso >/tmp/res. txt & -starts a program ctrl+z -suspends the current program bg -puts the program in the background

We can list all daemons using the 'jobs' command.

jobs

Use the 'fg' command to bring background programs to the foreground.

fg % process id12.ipcs

The ipcs command reports the status of the interprocess communication facility. (shared memory, semaphores and message queues)

Use the-p parameter in conjunction with-m, -s, or-q to obtain the process ID of the associated interprocess communication.

ipcs -p -m

The following screenshot lists the creator ID and process ID of the process that most recently accessed the shared memory segment.

At this point, I believe that everyone has a deeper understanding of "what are the commonly used process management commands in Linux", so you may wish to actually operate it! Here is the website, more related content can enter the relevant channels for inquiry, pay attention to us, continue to learn!

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

Development

Wechat

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

12
Report