Basic use of PS command

Source: Internet
Author: User
Tags egrep

basic knowledge of the process

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 (Received signal does not wake up and cannot be 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)

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

command Format
PS [parameter]

Command Function
used to display the status of the current process

Command Parameters
a Show All processes

-a displays all programs under the same terminal

-A Show All processes

C Displays the real name of the process

-N Reverse Selection

-e equals "-A"

e Display Environment variables

F show the relationship between programs

-H Display tree structure

R shows the process of the current terminal

T displays all programs for the current terminal

U specify all processes for the user

-au Show more detailed information

-aux Show all itineraries that contain other users

-c< commands > lists the status of the specified command

--lines< lines > number of rows displayed per page

--width< characters > number of characters displayed per page

--HELP Display Help information

--version Display version display


Several application examples of PS command
  1. Show All process information
    Ps-a
    Output as:
    [[email protected] document]$ ps-a PID TTY T        IME CMD 1?        00:00:01 Init 2?        00:00:00 Kthreadd 3?        00:00:00 migration/0 4?        00:00:00 ksoftirqd/0 5?        00:00:00 stopper/0 6?        00:00:00 watchdog/0 7?        00:00:00 MIGRATION/1 8?        00:00:00 STOPPER/1 9?        00:00:00 KSOFTIRQD/1 10?        00:00:00 WATCHDOG/1 11?        00:00:00 MIGRATION/2 12?        00:00:00 STOPPER/2 13?        00:00:00 KSOFTIRQD/2 14?        00:00:00 WATCHDOG/2 15?        00:00:00 MIGRATION/3 16? 00:00:00 STOPPER/3 ... (omitted) 
  2. Show processes related to specified user information
    Ps-u Zhang
    The output is:
    [Email protected] ~]$ ps-u Zhang  PID TTY time          CMD 2657?        00:00:00 gnome-keyring-d 2667?        00:00:00 gnome-session 2675?        00:00:00 dbus-launch 2676?        00:00:00 Dbus-daemon 2739?        00:00:04 gconfd-2 2746?        00:00:06 gnome-settings-2754?        00:00:00 gvfsd 2758?        00:00:00 Seahorse-daemon 2767?        00:00:04 gnome-panel 2773?        00:00:12 pulseaudio 2781?        00:00:00 gconf-helper 2788?        00:00:07 Nautilus 2790?        00:00:00 bonobo-activati 2796?        00:00:04 wnck-applet 2798?        00:00:00 trashapplet 2804?        00:00:00 gvfsd-trash 2806?        00:00:00 Gvfs-gdu-volume ... Omitted
  3. Show all process information, along with command line
    Ps-ef
    The output is:
    [[email protected] ~]$ ps-efuid PID PPID C stime TTY time cmdroot 1 0 0 14:26?        00:00:01/sbin/initroot 2 0 0 14:26?        00:00:00 [Kthreadd]root 3 2 0 14:26?        00:00:00 [Migration/0]root 4 2 0 14:26?        00:00:00 [Ksoftirqd/0]root 5 2 0 14:26?        00:00:00 [Stopper/0]root 6 2 0 14:26?        00:00:00 [Watchdog/0]root 7 2 0 14:26?        00:00:00 [Migration/1]root 8 2 0 14:26?        00:00:00 [Stopper/1]root 9 2 0 14:26?        00:00:00 [Ksoftirqd/1]root 10 2 0 14:26?        00:00:00 [Watchdog/1]root 11 2 0 14:26?        00:00:00 [Migration/2]root 12 2 0 14:26?        00:00:00 [Stopper/2]root 13 2 0 14:26?        00:00:00 [Ksoftirqd/2]root 14 2 0 14:26?        00:00:00 [Watchdog/2]root 15 2 0 14:26? 00:00:00 [Migration/3]root 16    2 0 14:26?        00:00:00 [Stopper/3]root 17 2 0 14:26?        00:00:00 [Ksoftirqd/3]root 18 2 0 14:26?        00:00:00 [Watchdog/3]root 19 2 0 14:26?        00:00:00 [Events/0]root 20 2 0 14:26?        00:00:00 [events/1]root 21 2 0 14:26?        00:00:00 [Events/2]root 22 2 0 14:26?        00:00:00 [Events/3]root 23 2 0 14:26?        00:00:00 [Cgroup]root 24 2 0 14:26?        00:00:00 [Khelper]root 25 2 0 14:26?        00:00:00 [Netns]root 26 2 0 14:26? 00:00:00 [Async/mgr] ... Omitted
  4. PS and grep common combination usage, find specific process
    Ps-ef | grep ssh
    Output as:
    [[email protected] ~]$ PS -ef |        grep sshroot 1980 1 0 14:26? 00:00:00/usr/sbin/sshdzhang 21211 21146 0 19:35 pts/0 00:00:00 grep ssh 

  5. The current user is currently logged in the PID and related information listed
    Ps-l
    The output is:
    [[email protected] ~]$ ps-lf s   UID   PID  PPID  C PRI  NI ADDR SZ wchan  TTY time          CMD0 s   500 21 146 21143  0   0-27050 wait   pts/0 00:00:00 bash0    R 21308 21146  1   0 -27032-      pts/0    00:00:00 PS
    Description
    The meaning of the relevant information:

    F represents the flag of this program, 4 represents the user as Super user

    S represents the status of this program (STAT), and the significance of each stat will be described in the text

    The UID program is owned by the UID.

    PID is the ID of this program!

    PPID is the ID of its parent program

    Percentage of resources used by the C CPU

    PRI this is the abbreviation for priority (precedence order), which is described in detail later

    NI is a nice value

    ADDR This is the kernel function, which points out the part of the program that is in memory. If it's a running program, it's usually "-"

    SZ-Used memory size

    Wchan whether the program is currently in operation, if it is-indicates that it is operating

    TTY Login Terminal Location

    Time used to consume the CPU.

    CMD issued by the command

    In the case of presets, PS only lists the PID associated with the current bash shell, so when I use ps-l, there are only two PID.
  6. List all the programs that are currently in memory
    PS aux
    The output is:
    [[email protected] ~]$ PS auxuser PID%cpu%MEM VSZ RSS TTY STAT START time Commandroot 1        0.0 0.0 19364 1360?        Ss 14:26 0:01/sbin/initroot 2 0.0 0.0 0 0?        S 14:26 0:00 [kthreadd]root 3 0.0 0.0 0 0?        S 14:26 0:00 [migration/0]root 4 0.0 0.0 0 0?        S 14:26 0:00 [ksoftirqd/0]root 5 0.0 0.0 0 0?        S 14:26 0:00 [stopper/0]root 6 0.0 0.0 0 0?        S 14:26 0:00 [watchdog/0]root 7 0.0 0.0 0 0?        S 14:26 0:00 [migration/1]root 8 0.0 0.0 0 0?        S 14:26 0:00 [stopper/1]root 9 0.0 0.0 0 0?        S 14:26 0:00 [ksoftirqd/1]root 10 0.0 0.0 0 0?        S 14:26 0:00 [watchdog/1]root 11 0.0 0.0 0 0?        S 14:26 0:00 [migration/2]root 12 0.0 0.0 0 0? S    14:26 0:00 [STOPPER/2] ... Omitted
  7. Lists process displays similar to the program tree
    Ps-axjf
    The output is:
    [[email protected] ~]$ Ps-axjfwarning:bad syntax, perhaps a bogus '-'?  See/usr/share/doc/procps-3.2.8/faq PPID PID pgid SID TTY tpgid STAT UID time COMMAND 0 2 0 0           ?           -1 S 0 0:00 [Kthreadd] 2 3 0 0?           -1 S 0 0:00 \_ [migration/0] 2 4 0 0?           -1 S 0 0:00 \_ [ksoftirqd/0] 2 5 0 0?           -1 S 0 0:00 \_ [stopper/0] 2 6 0 0?           -1 S 0 0:00 \_ [watchdog/0] 2 7 0 0?           -1 S 0 0:00 \_ [MIGRATION/1] 2 8 0 0?           -1 S 0 0:00 \_ [STOPPER/1] 2 9 0 0?           -1 S 0 0:00 \_ [KSOFTIRQD/1] 2 10 0 0?           -1 S 0 0:00 \_ [WATCHDOG/1] 2 11 0 0?           -1 S 0 0:00 \_ [MIGRATION/2] 2 12 0 0? -1 S 0 0:00 \_ [STOPPER/2] 2 13 0 0? -1 S 0 0:00 \_ [KSOFTIRQD/2] ... Omitted
  8. Find the PID number associated with a few services
    PS aux | Egrep ' (cron|syslog) '
    The output is:
    [Email protected] ~]$ Ps-aux | Egrep ' (cron|syslog) ' Warning:bad syntax, perhaps a bogus '-'? See/usr/share/doc/procps-3.2.8/faqroot      1552  0.0  0.0 249096  1120?        Sl   14:26   0:00/sbin/rsyslogdroot      2360  0.0  0.0 117328  1392?        Ss   14:26   0:00 Crond


Basic use of PS command

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.