Shell Record-shell Script Basics (v)

Source: Internet
Author: User
Tags syslog

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:

    • DNon-interruptible uninterruptible sleep (usually IO)
    • RRun runnable (on run queue)
    • SInterrupt Sleeping
    • TStop traced or stopped
    • ZZombie a defunct ("zombie") process
1. Command Format

ps[parameters]

2. Command function

Used to display the status of the current process

3. Command Parameters
    • aShow All Processes
    • -aShow All programs under the same terminal
    • -AShow All Processes
    • cShow the real name of the process
    • -NReverse Selection
    • -eequals "-A"
    • eDisplay environment variables
    • fShow relationships between programs
    • -HShow tree structure
    • rShow process for current terminal
    • TShow All programs for the current terminal
    • uSpecify all processes for a user
    • -auShow more detailed information
    • -auxShow all itineraries that contain other users
    • -C< commands > lists the status of the specified command
    • --lines< rows > number of rows displayed per page
    • --width< number of characters > characters displayed per page
    • --helpDisplay Help information
    • --versionShow version Show instance 1: Show all process information commands:ps -AExample 2: Display the specified user information command:ps -u rootExample 3: Show all process information, along with command-line commands:ps -efExample 4:ps with grep common use combination to find specific process commands:ps -ef|grep ssh
      ps -lF S   UID    PID   PPID  C PRI  NI ADDR SZ WCHAN  TTY          TIME CMD0 S  1000   2168   2167  0  80   0 - 28869 wait   pts/0    00:00:00 bash
      Shelldescribe the meaning of the relevant information:
      FFlag for this program, 4 for user Super User
      SRepresents the status of this program (STAT), and the significance of each stat will be described in the text
      UIDThe program is owned by the UID
      PIDThat's the ID of the program.
      PPIDis the ID of its ancestor parent program
      CPercent of resources used by the CPU
      PRIThis is the abbreviation for priority (precedence order), which is described in detail later
      NIThis is a nice value, and in the next section we will continue to introduce
      ADDRThis is the kernel function, which indicates the part of the program that is in the memory. If it's a running program, it's usually "-"
      SZMemory size to use
      WCHANWhether the procedure is currently in operation, if it is-indicates that it is operating
      TTYTerminal location of the logged-in person
      TIMEThe CPU time that was used off.
      CMDWhat is the order issued?
      In the case of a preset,psOnly the PID associated with the bash shell currently in place is listed, so when I use theps -l, there are only three PID.Example 6: List all currently in-memory programsCommand:
      ps aux
      Output:
      [[email protected] ~]$ ps auxUSER        PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMANDroot          1  0.1  0.3 125084  3612 ?        Ss   19:58   0:03 /usr/lib/syste..
      Description:
      USER: The process belongs to that 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, and if it is not related to the terminal, it will be displayed?, in addition, tty1-tty6Is the computer above the login program, if pts/0, and so on, 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 (which 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 time that the process actually uses the CPU to operate
      COMMAND: The actual instruction of the program
    • Example 7: List programs that resemble the program tree display commands:
      ps -axjf
      Example 8: Find out the PID number command execution and output related to cron and syslog services:
       ps aux | egrep ‘(cron|syslog)‘
    • Example 9 (Other):1. Can be used | Pipe and more connect up paging view
      Command:
      ps -aux |more
      Shell2. Show all the processes and output to the Ps001.txt file
      Command:
      ps -aux > ps001.txt
      Shell3. Outputs the specified field
      Command:
       ps -o pid,ppid,pgrp,session,tpgid,comm

Shell Record-shell Script Basics (v)

Related Article

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.