linux common commands -ps

What is PS command

See its man page can be seen, ps command can give a snapshot of the current processes in the system. It can capture process status of an event in the system. If you want to view the status of constantly updated, you can use the top command.

ps command supports syntax used in three of

    UNIX-style options can be combined and the former option must have "-" hyphen
    BSD-style options can be combined, but not before there are options "-" hyphen
    long options GNU style, there are two options before. " - "hyphen

We can mix these types of style, but may conflict. As used herein, UNIX-style ps command. Here is an example using more ps command in everyday life.
1. ps command with no arguments

This is a basic ps use. Execute this command in the console and see the results.

 The results will show four default information.

    PID: command (CMD) of the running process ID
    TTY: position command is running (terminal)
    the TIME: the CPU processing time running the command occupied
    CMD: The command process running

This information is not sorted when displayed.

2. Display all the current process

Use -a parameter. -a representative of all. At the same time plus x parameter will be displayed without the controlling terminal.

$ Ps -ax 

 The results of this command may be very long. For ease of viewing, and the pipe may be combined to use less command.

$ ps -ax | less
 
The user filtering process

In the case of the need for specific user processes, we can use the -u parameter. For example, we want to see users 'kseven' process, you can use the following command:

$ Ps -u kseven

4. The filtering process through the use of memory and cpu

Maybe you want to put the results in accordance with the CPU or memory usage to screen, so you find what process is using 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 less command to filter and pipes.

The default result set is not sorted. You can sort by --sort command.

The CPU using an ascending sort

$ Ps aux --sort -pcpu | less

The memory using an ascending sort

$ Ps aux --sort -pmem | less

We can also combine them into one command and displays the first 10 results through the pipeline:

$ Ps aux --sort -pcpu, + pmem | head -n 10

 5. filtered through the process name and PID

Use the -C parameter, followed by the name of the process that you are looking for. For example, you want to display a message called getty process, you can use the following command:

$ ps -C getty

If you want to see more detail, we can use the -f option to view a list of formatted information:

$ ps -f -C getty

6. The process according to filter thread

If we want to know the thread-specific process, you can use -L parameter, followed by the specific PID.

$ Ps -L 1213

7. The tree display process

Sometimes we want to show the process tree structure, you can use -axjf parameters.

$ps -axjf

 Or you can use another command.

$ pstree

8. Display Security Information

If you want to see now who logged into your server. You can use the ps command with the parameters:   

$ ps -eo pid,user,args

-E parameter displays all process information, -o parameter control output. Pid, User and Args parameter display PID, the user running the application and the application.
Keywords can be used with the -e parameter is args, cmd, comm, command, fname, ucmd, ucomm, lstart, bsdstart and start.

9. The process of formatting the 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 information about this process, you can use the following command:

$ ps -U root -u root u 

-U parameter screening process by the real user ID (RUID), it will choose the real user name or ID from the user list. That is the real user of the process of actually creating the user.

-u parameter is used to screen for 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 are the above command output:
10 PS using real-time monitoring process status

ps command will show the current state of your system process, but the result is static.

When there is a situation, we need to be screened by the CPU and memory usage process as mentioned above, the fourth point, and we hope that the results can be refreshed once per second. To this end, 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’

The view here is not as dynamic top or htop command. But the benefits of using ps is a field that you can customize the display, you can select the fields you want to view.

For example, if you only need to look at information about the user named 'pungki', you can use the following command:

Watch -n $ 1 '-aux ps -u u pungki --sort -pmem, -pcpu | head 20 '

 

Guess you like

Origin www.cnblogs.com/qixifly/p/12017839.html