Linux Operations PS Command

Source: Internet
Author: User
Tags syslog egrep

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
    1. Command format:
    ps[parameters]
    2. Command function:
    Used to display the status of the current process
    3. 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
    4. Usage examples:
    Example 1: Show all process information
    Command:
    Ps-a
    Output:
    [Email protected] test6]# ps-a
    PID TTY Time CMD
    1? 00:00:00 Init
    2? 00:00:01 migration/0
    5 y 00:00:00 ksoftirqd/0
    6} 00:00:01 MIGRATION/1
    3 y 00:00:00 KSOFTIRQD/1
    6? 00:29:57 events/0
    7? 00:00:00 EVENTS/1
    8? 00:00:00 Khelper
    49? 00:00:00 Kthread
    54? 00:00:00 kblockd/0
    55? 00:00:00 KBLOCKD/1
    56? 00:00:00 Kacpid
    217? 00:00:00 cqueue/0
    ...... Omit partial results
    Description
    Example 2: Displaying specified user information
    Command:
    Ps-u Root
    Output:
    [Email protected] test6]# ps-u root
    PID TTY Time CMD
    1? 00:00:00 Init
    0} 00:00:01 migration/0
    3? 00:00:00 ksoftirqd/0
    4? 00:00:01 MIGRATION/1
    5? 00:00:00 KSOFTIRQD/1
    6? 00:29:57 events/0
    7? 00:00:00 EVENTS/1
    8? 00:00:00 Khelper
    49? 00:00:00 Kthread
    54? 00:00:00 kblockd/0
    55? 00:00:00 KBLOCKD/1
    56? 00:00:00 Kacpid
    ...... Omit partial results
    Description
    Example 3: Show all process information, along with command line
    Command:
    Ps-ef
    Output:
    [Email protected] test6]# Ps-ef
    UID PID PPID C stime TTY time CMD
    Root 1 0 0 Nov02? 00:00:00 Init [3]
    Root 2 1 0 Nov02? 00:00:01 [migration/0]
    Root 3 1 0 Nov02? 00:00:00 [ksoftirqd/0]
    Root 4 1 0 Nov02? 00:00:01 [MIGRATION/1]
    Root 5 1 0 Nov02? 00:00:00 [KSOFTIRQD/1]
    Root 6 1 0 Nov02? 00:29:57 [events/0]
    Root 7 1 0 Nov02? 00:00:00 [EVENTS/1]
    Root 8 1 0 Nov02? 00:00:00 [Khelper]
    Root 1 0 Nov02? 00:00:00 [Kthread]
    Root 0 Nov02? 00:00:00 [kblockd/0]
    Root 0 Nov02? 00:00:00 [KBLOCKD/1]
    Root 0 Nov02? 00:00:00 [Kacpid]
    ...... Omit partial results
    Description
    Example 4:ps and grep common use combinations to find specific processes
    Command:
    Ps-ef|grep SSH
    Output:
    [[email protected] test6]# ps-ef|grep SSH
    Root 2720 1 0 Nov02? 00:00:00/usr/sbin/sshd
    Root 17394 2720 0 14:58? 00:00:00 sshd: [Email protected]/0
    Root 17465 17398 0 15:57 pts/0 00:00:00 grep ssh
    Description
    Example 5: Make a list of the PID and related information that is currently your own log in
    Command:
    Ps-l
    Output:
    [Email protected] test6]# ps-l
    F S UID PID PPID C PRI NI ADDR SZ Wchan TTY time CMD
    4 S 0 17398 17394 0 0-16543 wait pts/0 00:00:00 bash
    4 R 0 17469 17398 0 0-15877-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 This is a nice value, and in the next section we will continue to introduce
    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.
    What are the commands that CMD has issued?
    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 three PID.
    Example 6: List all currently in-memory programs
    Command:
    PS aux
    Output:
    [[Email protected] test6]# PS aux
    USER PID%cpu%MEM VSZ RSS TTY STAT START time COMMAND
    Root 1 0.0 0.0 10368 676? Ss Nov02 0:00 init [3]
    Root 2 0.0 0.0 0 0? s< Nov02 0:01 [migration/0]
    Root 3 0.0 0.0 0 0? SN Nov02 0:00 [ksoftirqd/0]
    Root 4 0.0 0.0 0 0? s< Nov02 0:01 [MIGRATION/1]
    Root 5 0.0 0.0 0 0? SN Nov02 0:00 [KSOFTIRQD/1]
    Root 6 0.0 0.0 0 0? s< Nov02 29:57 [events/0]
    Root 7 0.0 0.0 0 0? s< Nov02 0:00 [EVENTS/1]
    Root 8 0.0 0.0 0 0? s< Nov02 0:00 [Khelper]
    Root 49 0.0 0.0 0 0? s< Nov02 0:00 [Kthread]
    Root 54 0.0 0.0 0 0? s< Nov02 0:00 [kblockd/0]
    Root 55 0.0 0.0 0 0? s< Nov02 0:00 [KBLOCKD/1]
    Root 56 0.0 0.0 0 0? s< Nov02 0:00 [Kacpid]
    ...... Omit partial results
    Description
    User: The process belongs to the user account
    PID: The number of the process
    %cpu: Percentage of CPU resources that the process uses
    %MEM: Percentage of physical memory occupied by this process
    VSZ: The amount of virtual memory that the process uses (Kbytes)
    RSS: The amount of fixed memory that the process occupies (Kbytes)
    TTY: The process is operating on that terminal, if it is not related to the terminal, then display?, in addition, TTY1-TTY6 is the machine above the login program, if it is pts/0 and so on, it is represented by the network connected to the host computer program.
    STAT: The current state of the program, the main state has
    R: The program is currently in operation or can be operated
    S: The program is currently sleeping (can be said to be idle) but can be awakened by certain signals (signal).
    T: The program is currently detecting or stopping
    Z: The program should have been terminated, but the parent program could not properly terminate him, causing the state of the zombie (Xinjiang Corpse) program
    Start: The time that the process was triggered to start
    Time: The process actually uses the CPU to run
    Command: The actual instruction of the program
    Example 7: Listing programs showing similar program trees
    Command:
    Ps-axjf
    Output:
    [Email protected] test6]# PS-AXJF
    Warning:bad syntax, perhaps a bogus '-'? See/usr/share/doc/procps-3.2.7/faq
    PPID PID pgid SID TTY tpgid STAT UID time COMMAND
    0 1 1 1? -1 Ss 0 0:00 init [3]
    1 2 1 1? -1 s< 0 0:01 [migration/0]
    1 3 1 1? -1 SN 0 0:00 [ksoftirqd/0]
    1 4 1 1? -1 s< 0 0:01 [MIGRATION/1]
    1 5 1 1? -1 SN 0 0:00 [KSOFTIRQD/1]
    1 6 1 1? -1 s< 0 29:58 [events/0]
    1 7 1 1? -1 s< 0 0:00 [EVENTS/1]
    1 8 1 1? -1 s< 0 0:00 [Khelper]
    1 49 1 1? -1 s< 0 0:00 [Kthread]
    49 54 1 1? -1 s< 0 0:00 _ [kblockd/0]
    49 55 1 1? -1 s< 0 0:00 _ [KBLOCKD/1]
    49 56 1 1? -1 s< 0 0:00 _ [kacpid]
    Description
    Example 8: Find PID numbers related to cron and syslog services
    Command:
    Output:
    [[Email protected] test6]# PS aux | Egrep ' (cron|syslog) '
    Root 2682 0.0 0.0 83384 2000? Sl Nov02 0:00/sbin/rsyslogd-i/var/run/syslogd.pid-c 5
    Root 2735 0.0 0.0 74812 1140? Ss Nov02 0:00 Crond
    Root 17475 0.0 0.0 61180 832 pts/0 s+ 16:27 0:00 egrep (cron|syslog)
    [Email protected] test6]#
    Description
    Other examples:
  6. Can be used | Pipe and more connect up paging view
    Command:
    Ps-aux |more
  7. Show all the processes and output to the Ps001.txt file
    Command:
    Ps-aux > Ps001.txt
  8. Outputs the specified field
    Command:
    Ps-o Pid,ppid,pgrp,session,tpgid,comm
    Output:
    [Email protected] test6]# Ps-o Pid,ppid,pgrp,session,tpgid,comm
    PID PPID pgrp sess tpgid COMMAND
    17398 17394 17398 17398 17478 Bash
    17478 17398 17478 17398 17478 PS

Linux Operations 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.