"Linux Commands and Tools" PS

Source: Internet
Author: User

The PS command in Linux is the abbreviation for process status. The PS command is used to list those processes that are currently running on the system. The PS command lists the current snapshots of those processes, which are those that are executing the PS command at the moment, and if you want to display process information dynamically, you can use the top command.

To monitor and control the process, you must first understand the current process, that is, you need to see the current process, and the PS command is the most basic and very powerful process view command. Use this command to determine which processes are running and running, whether the process is complete, if the process is zombie, which processes are consuming too many resources, and so on. In short, most of the information can be obtained by executing the command.

PS gives us a one-time view of the process, it provides a view of the results is not dynamic continuous, if you want to monitor the process, you should use the top tool.

The KILL command is used to kill the process.

There are 5 states of processes on Linux:

1. Running (running or waiting in the running queue)

2. Interrupt (dormant, blocked, waiting for a condition to form or receive a signal)

3. Non-interruptible (receive signal does not wake up and not run, process must wait until interrupt occurs)

4. Zombie (The process has been terminated, but the process descriptor exists until the parent process calls WAIT4 () after the system call is released)

5. Stop (process received Sigstop, SIGSTP, Sigtin, Sigtou signal after stop running run)

PS Tool identifies 5 status codes for the process:

D non-interruptible uninterruptible sleep (usually IO)

R run runnable (on run queue)

S Interrupt Sleeping

T stop traced or stopped

Z Zombie a defunct ("zombie") process

  

PS command supports three types of syntax formats used

UNIX style, options can be grouped together, and the option must have "-" hyphens before

BSD style, options can be grouped together, but cannot have a "-" hyphen before the option

GNU style long option with two "-" hyphens in front of options


We can mix these styles, but there may be conflicts. This article uses the UNIX-style PS command.

  

Common parameters:

-a displays all programs under the same terminal,

-aux Show all processes that contain other users

Common option combinations:

1. Execute PS command without parameters

This is a basic PS to use. Execute this command from the console and view the results.

Execute PS command without option

The result is 4 columns of information displayed by default.

    • PID: The process number of the command (CMD) running
    • TTY: Where the command is running (terminal)
    • Time: CPU processing times consumed by the command that is running
    • CMD: The command that the process runs

This information is not sorted when it is displayed.

2. Show all current processes

Use the-a parameter. -a representsall. Plus the x parameter shows the process without the control terminal.

    1. $ PS -ax

The result of this command may be very long. For ease of viewing, it can be used in conjunction with less commands and pipelines.

    1. $ PS -ax | Less

PS All information

3. Based on user filtering process

We can use the- u parameter when we need to see a particular user process. For example, we want to see the user ' Pungki ' process, you can use the following command:

    1. $ PS -u pungki

Filter by user

4. Filtering processes through CPU and memory usage

You might 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:

    1. $ PS -aux | Less

Show full information

When the results are long, we can use the pipe and less command to filter.

The default result set is not well-ordered. Can be sorted by --sort command.

Sort Ascending According to CPU usage

    1. $ PS -aux --sort -pcpu | Less

Sort by CPU usage

Sort Ascending According to memory usage

    1. $ PS -aux --sort -pmem | Less

Sort by memory usage

We can also merge them into one command and display the top 10 results by pipeline:

  $ PS -aux --sort -pcpu, +pmem | head -n ten

Resources:

1. https://linux.cn/article-4743-1.html

2. http://www.cnblogs.com/peida/archive/2012/12/19/2824418.html

"Linux Commands and Tools" PS

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.