Linux as a Unix-derived operating system, Linux has built-in view of the current process tool ps. This tool can be used in the command line.
What is the PS command
See the man page it can be seen, ps command can give a snapshot of the current processes in the system. It can capture system process status in an event. If you want to see the updated status, you can use the top command.
ps command supports syntax used in three of
UNIX-style options can be combined, and there must be options before "-" hyphen
BSD-style options can be combined, but not before there is an option "-" hyphen
GNU-style long options, there are two options before "-" hyphen
We can mix these types of style, but a conflict may occur. As used herein, UNIX-style ps command. There is more use of the ps command in everyday life examples.
1. execute ps command with no arguments
This is a basic ps use. Execute this command in the console and see the results.
The results show four default message.
PID: running command (CMD) process ID
TTY: position command is running (terminal)
TIME: running the command of CPU processing time
CMD: Command run by this process
This information is not sorted in the display.
2. Display all the current process
Use -a parameter. -a representative of all. At the same time plus x parameter will show no controlling terminal.
$ Ps -ax
The results of this command may be very long. For ease of viewing, can be combined with less command and pipes to use.
$ Ps -ax | less
3. The user filtering process
In the need for specific user processes, we can use the -u parameter. For example, we want to view the user 'pungki' process can use the following command:
$ Ps -u pungki
4. cpu and memory usage to the filtering process
Maybe you want to put the results in accordance with the CPU or memory usage to filter, so you find out which process is using your resources. To do this, we can use the aux parameter to display comprehensive information:
$ Ps -aux | less
When the result of a long time, we can use the command to filter pipes and less.
The default result set is not sorted. You can be sorted by --sort command.
According to CPU usage in ascending order
$ Ps -aux --sort -pcpu | less
According to an ascending sort memory usage
$ Ps -aux --sort -pmem | less
We also can combine them into a command and displays the first 10 results through the pipeline:
$ Ps -aux --sort -pcpu, + pmem | head -n 10
5. Through the process name and PID filter
Use the -C parameter, followed by the name of the process you are looking for. For example, want to display a message named getty process, you can use the following command:
$ Ps -C getty
If you want to see more detail, we can see a list of information formatted using the -f parameter:
$ Ps -f -C getty
6. The thread to the filtering process
If we want to know the thread-specific process, you can use the -L argument, followed by a particular PID.
$ Ps -L 1213
7. The tree display process
Sometimes we want to show the process tree, you can use -axjf parameters.
$ Ps -axjf
Or you can use another command.
8. Display Security Information
If you want to see who is now logged into your server. You can use the ps command with the parameters:
$ Ps -eo pid, user, args
Parameter -e show all processes information, -o parameter control output. Pid, User and Args parameter display PID, the user runs the application and the application.
Keywords can be used in conjunction with the -e parameter is args, cmd, comm, command, fname, ucmd, ucomm, lstart, bsdstart and start.
9. The process of formatting output root user (real or effective UID) is created
When the system administrator wants to see the process run by the root user and other relevant information about this process, you can use the following command:
$ Ps -U root -u root u
-U Parameter by real user ID (RUID) screening process, it will choose the real user name or ID from the user list. That is the real user of the process of the actual creation of the user.
-u parameter is used to screen the effective user ID (EUID).
U parameter is used to determine the final format for output to the user by the User, PID,% CPU,% MEM, VSZ, RSS, TTY, STAT, START, TIME and COMMAND these columns.
Here is the output of the above command:
10. Use the PS real-time monitoring process status
ps command will display the current process status of your system, but this result is static.
When there is a case, we need something like the CPU and memory usage screening process mentioned above, the fourth point, and we hope that the results can be refreshed once per second. For this reason, we can watch the ps command and the command together.
$ Watch -n 1'ps -aux --sort -pmem, -pcpu '
If the output is too long, we can limit it, such as before 20, we can use the head command to do.
$ Watch -n 1'ps -aux --sort -pmem, -pcpu | head 20 '
Here dynamic view is not as top or htop command. But using ps field advantage is that you can customize the display, you can choose what you want to see the field.
For example, if you just look at the name 'pungki' user, you can use the following command:
$ Watch -n 1'ps -aux -U pungki u --sort -pmem, -pcpu | head 20 '
You may use the ps command will be a day to monitor your Linux system. But in fact, you can generate a variety of reports you need via parameters ps command.
Another advantage is the ps command ps a variety of Linux systems are installed by default, so you just used on the line.
Do not forget by man ps to see more parameters. (LCTT Annotation: As the ps command ancient and important, so it is in different parameters of UNIX, BSD, Linux and other systems are not the same, so if you are not using Linux system, please consult your documentation for specific parameters available. )