Linux is a derivative of Unix operating system
, Linux has built-in tools to view the current process ps. This tool can be used on the command line.
What is the PS command?
Check its man page to see that the ps command gives a snapshot of the process in the current system. It captures the state of the system in a certain event. If you want to keep updating this state of view, you can use the top command.
The ps command supports three syntax formats used
We can mix these styles, but there may be conflicts. This article uses the UNIX-style ps command. Here are examples of ps commands that are used more often in everyday life.
1. Execute the ps command without arguments
This is a basic ps use. Execute this command in the console and see the results.
The results will display 4 columns of information by default.
These information is not sorted when displayed.
2. Show all current processes
Use the -a parameter. -a stands for all. Adding the x parameter at the same time will show the process without the control terminal.
$ ps -ax
The result of this command may be very long. For ease of viewing, it can be used in conjunction with the less command and pipeline.
$ ps -ax |
Less
3. According to the user filtering process
We can use the -u parameter if we need to view a specific user process. For example, if we want to view the user & rsquo;pungki’ process, you can use the following command:
$ ps -u pungki
4. Filter the process through cpu and memory usage
Maybe you I want to filter the results by CPU or memory usage, so you can find which process is taking up your resources. To do this, we can use the aux parameter to display comprehensive information:
$ ps -aux |
Less
When the result is very long, we can use the pipe and the less command to filter.
The default result set is unordered. Can be sorted by the –sort command.
Sort in ascending order according to CPU usage
$ ps -aux --sort -pcpu |
Less
Sorting in ascending order based on memory usage
$ ps -aux --sort -pmem |
Less
We can also merge them into one command and display the top 10 results through the pipeline:
$ ps -aux --sort -pcpu,+pmem |
Head -n 105. Filter by process name and PID
Use the -C parameter followed by the name of the process you are looking for. For example, if you want to display information about a process named getty, you can use the following command:
$ ps -C getty
If you want to see more details, we can use - f parameter to view a list of formatted information:
$ ps -f -C getty
6. Filter the process according to the thread
If we want to know the thread of a particular process, you can use The -L parameter, followed by a specific PID.
$ ps -L 1213
7. Tree Display Process
Sometimes we want to display the process in a tree structure, you can use the -axjf parameter.
$ps -axjf
Or you can use another command.
$pstree
8. Displaying Security Information
If you want to see who is currently logged into your server. You can use the ps command with the relevant parameters:
$ ps -eo pid,user,args
parameter -e displays all process information, and the -o parameter controls the output. The Pid, User and Args parameters show the 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. Formatting 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, The following command:
$ ps -U root -u root u
-U The parameter filters the process by real user ID (RUID), which selects the real username or ID from the list of users. 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 in the format for the user. It consists of the User, PID, %CPU, %MEM, VSZ, RSS, TTY, STAT, START, TIME and COMMAND columns.
There are output results of the above command:
10. Using PS to monitor process status in real time
ps command will display the current process status of your system, but This result is static.
When there is a situation, we need to filter the process by CPU and memory usage as mentioned in the fourth point above, and we want the result to be refreshed every second. To do this, we can combine the ps command with the watch command.
$ watch -n 1 ‘ps -aux --sort -pmem, -pcpu’
If the output is too long, we can also limit it, such as the first 20, we can use The head command is done.
$ watch -n 1 ‘ps -aux --sort -pmem, -pcpu |
Head 20’
The dynamic view here is not like the top or htop command. 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 look at the information named ’pungki’user, you can use the following command:
$ 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 various reports you need by using the parameters of the ps command.
Another advantage of the ps command is that ps is installed by default on all Linux systems, so you only need to use it.
Don't forget to see more parameters by man ps. (LCTT: Because the ps command is old and important, it has different parameters on different UNIX, BSD, Linux, etc., so if you are not using a Linux system, please consult your documentation for specific parameters. )
win7 There are a lot of tricks, if used well, can make the win7 system get no small optimization. No
1. Introduction to LVS1. Provide high availability and load balancing capabilities for application s
Under Linux, the IDE device is named after hd. Generally, there are two IDE interf
1. Nothing to teach, teach you to look at the system version first (fatly remember the first time to
Linux operating system history command is fully controlled
Linux change file /device owner method
Teaching: Help you easily get the software installation of Linux system
Linux using NTP service management /synchronization server time
Shorewall firewall installation and configuration method under Linux
Linux to the desktop still takes
Linux shell different binary data conversion (binary, octal, hexadecimal, base64)
Easily implement Internet filtering under Linux
Linux installation using cacti
Win10 will support Chakra Javascript engine across multiple applications.
GHOST restore system appears "Decompression error, Abort?" Solution
How to block webpage floating ads in Win7 system
How to quickly shut down Windows 8 Developer Preview?
Win7 forbids windows to automatically maximize
The hazards and symptoms of computer viruses
Win8 system U disk 0 bytes can not be formatted how to solve?
Windows8 perfect solution to mandatory driver signatures
Win10/Win8.1/Win7 comprehensive performance evaluation big secret (4): storage performance
Win7 command window prompts "javac is not an internal or external command" how to solve?