In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the relevant knowledge of "what are the ps commands commonly used in the Linux system?" in the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Linux as a derivative operating system of Unix, Linux has built-in tool ps to view the current process. This tool can be used on the command line
What is the PS command?
Looking at its man manual, you can see that the ps command gives a snapshot of the processes in the current system. It can capture the process state of the system in a certain event. If you want to update this status constantly, you can use the top command.
The ps command supports three syntax formats used
UNIX style, options can be grouped together, and options must be preceded by a "-" hyphen
BSD style, options can be combined together, but options cannot be preceded by a "-" hyphen
GNU style long option with two "-" hyphens before the option
We can mix these styles, but there may be conflicts. This article uses the UNIX-style ps command. Here are examples of using more ps commands in daily life.
1. Execute the ps command without arguments
This is a basic ps use. Execute this command in the console and view the results.
The result displays four columns of information by default.
PID: the process number of the running command (CMD)
TTY: the location where the command runs (terminal)
TIME: the CPU processing time taken by the running command
CMD: the command that the process runs
This information is not sorted when it is displayed.
two。 Show all current processes
Use the-a parameter. -a stands for all. At the same time, the x parameter will show the process without the control terminal.
The code is as follows:
$ps-ax
The result of this command may be long. For ease of viewing, you can use it in combination with less commands and pipes.
The code is as follows:
$ps-ax | less
3. Filter processes based on users
In cases where we need to view specific user processes, we can use the-u parameter. For example, to view the progress of user 'pungki', we can use the following command:
The code is as follows:
$ps-u pungki
4. Filter processes through cpu and memory usage
Maybe you want to filter the results by CPU or memory usage, so you can find out which process is taking up your resources. To do this, we can use the aux parameter to display comprehensive information:
The code is as follows:
$ps-aux | less
When the results are long, we can use pipes and less commands to filter.
The default result set is not sorted. You can sort it with the-- sort command.
Sort in ascending order based on CPU usage
The code is as follows:
$ps-aux-- sort-pcpu | less
Sort in ascending order according to memory usage
The code is as follows:
$ps-aux-- sort-pmem | less
We can also merge them into a single command and display the first 10 results through pipes:
The code is as follows:
$ps-aux-- sort-pcpu,+pmem | head-n 10
5. Filter by process name and PID
Use the-C parameter, followed by the name of the process you are looking for. For example, to display information about a process named getty, you can use the following command:
The code is as follows:
$ps-C getty
If you want to see more details, we can use the-f parameter to view the list of formatted information:
The code is as follows:
$ps-f-C getty
6. Filter processes based on threads
If we want to know the thread of a particular process, we can use the-L parameter, followed by a specific PID.
The code is as follows:
$ps-L 1213
7. Tree display process
Sometimes we want to display the process in a tree structure, using the-axjf parameter.
The code is as follows:
$ps-axjf
Or you can use another command.
The code is as follows:
$pstree
8. Display security information
If you want to see who has logged in to your server now. You can use the ps command plus related parameters:
The code is as follows:
$ps-eo pid,user,args
The parameter-e displays all process information, and the-o parameter controls the output. The Pid,User and Args parameters show PID, the user running the application, and the application.
The keywords that can be used with the-e parameter are args, cmd, comm, command, fname, ucmd, ucomm, lstart, bsdstart, and start.
9. Format the process created by the root user (real or valid UID)
When the system administrator wants to view the process run by the root user and other related information about this process, you can use the following command:
The code is as follows:
$ps-U root-u root u
The-U parameter filters the process by real user ID (RUID), which selects the real user name or ID from the user list. The real user is the user who actually created the process.
The-u parameter is used to filter the valid user ID (EUID).
The final u parameter is used to determine the output format for the user, which consists of the columns User, PID,% CPU,% MEM, VSZ, RSS, TTY, STAT, START, TIME and COMMAND.
Here is the output of the above command:
10. Monitoring process status in real time using PS
The ps command shows the current process status of your system, but the result is static.
When there is a situation, we need to filter the process by CPU and memory usage, as mentioned in point 4 above, and we want the results to be refreshed every second. To do this, we can combine the ps command with the watch command.
The code is as follows:
$watch-n 1'ps-aux-sort-pmem,-pcpu'
If the output is too long, we can also limit it, such as the first 20 items, which we can do with the head command.
The code is as follows:
$watch-n 1'ps-aux-- sort-pmem,-pcpu | head 20'
The dynamic view here is not like the top or htop commands. But the advantage of using ps is that you can define the fields that are displayed, and you can select the fields you want to view.
For example, if you only need to see the information of the user named 'pungki', you can use the following command:
The code is as follows:
$watch-n 1'ps-aux-U pungki u-- sort-pmem,-pcpu | head 20'
Conclusion
You may use the ps command to monitor your Linux system every day. But in fact, you can generate all kinds of reports you need through the parameters of the ps command.
Another advantage of the ps command is that ps is installed by default on all Linux systems, so all you have to do is use it.
Don't forget to check out more parameters through man ps. (LCTT translation note: because the ps command is old and important, it has different parameters in different UNIX, BSD, Linux and other systems, so if you are not using a Linux system, please refer to your documentation for specific available parameters. )
This is the end of the content of "what are the ps commands commonly used in the Linux system?" Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.