Linux command: View (PS)/kill (kill) process common operations and instructions

Overview

The ps (English spelling: process status) command is used to display the status of the current process, similar to the Windows Task Manager

You can use the kill command to interrupt and delete unnecessary programs at any time.

Syntax and parameters

ps [options] [--help]

Common parameters

  1. -A lists all processes
  2. -w display widening can display more information
  3. -au displays more detailed information
  4. -aux displays all processes containing other users
  5. -f displays UID, PID, PPIP, C, STIME, STIME, TTY, TIME, CMD fields
  6. -a: Displays programs executed under all terminals, except the stage job leader.
  7. a: Display all programs under the current terminal, including programs of other users.
  8. -e: The effect of this option is the same as specifying the "A" option.
  9. e: When listing programs, display the environment variables used by each program.

au(x) output format (column description)

USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND

Column description

  • USER: trip owner,用户名
  • UIDThe program is owned by this UID
  • PID: 进程ID(Process ID)
  • PPID·It is its上级父程序的ID
  • %CPU: occupied CPU usage,进程的cpu占用率
  • %MEM: Memory usage occupied by the process内存占用率
  • VSZ: The size of virtual memory occupied,进程所使用的虚存的大小(Virtual Size)
  • RSS: The size of memory occupied, the size of the resident set used by the process, or实际内存的大小,Kbytes字节
  • TTY: Minor device number of tty,与进程关联的终端(tty)
  • STAT: The status of this trip:
    • D: Uninterruptible sleep state (usually IO process)
    • R: Executing
    • S: stationary state
    • T: pause execution
    • Z: Does not exist but cannot be eliminated temporarily
    • W: Not enough memory pages available to allocate
    • <: High priority itinerary
    • N: low priority itinerary
    • L: There are memory pages allocated and locked in the memory (real-time system or A I/O)
  • START: trip start time,进程启动时间和日期
  • TIME: Execution time
  • COMMAND:Instruction executed

Usage examples

root:# ps aux
USER      PID       %CPU    %MEM    VSZ    RSS    TTY    STAT    START    TIME    COMMAND
smmsp    3521    0.0    0.7    6556    1616    ?    Ss    20:40    0:00    sendmail: Queue runner@01:00:00 f
root    3532    0.0    0.2    2428    452    ?    Ss    20:40    0:00    gpm -m /dev/input/mice -t imps2
htt    3563    0.0    0.0    2956    196    ?    Ss    20:41    0:00    /usr/sbin/htt -retryonerror 0
htt    3564    0.0    1.7    29460    3704    ?    Sl    20:41    0:00    htt_server -nodaemon
root    3574    0.0    0.4    5236    992    ?    Ss    20:41    0:00    crond
xfs    3617    0.0    1.3    13572    2804    ?    Ss    20:41    0:00    xfs -droppriv -daemon
root    3627    0.0    0.2    3448    552    ?    SNs    20:41    0:00    anacron -s
root    3636    0.0    0.1    2304    420    ?    Ss    20:41    0:00    /usr/sbin/atd
dbus    3655    0.0    0.5    13840    1084    ?    Ssl    20:41    0:00    dbus-daemon-1 --system

Display all processes and output to the specified file

Display all processes and output to ps001.txt file

ps -aux > ps001.txt

View the specified process

ps -ef # 显示所有进程信息,连同命令行
ps -ef | grep ssh # ps 与grep 常用组合用法,查找特定进程

UID、PID、PPIP、C、STIME、STIME、TTY 、TIME、 CMD

# ps -ef | grep php
root       794     1  0  2020 ?        00:00:52 php-fpm: master process (/etc/php/7.3/fpm/php-fpm.conf)
www-data   951   794  0  2020 ?        00:24:15 php-fpm: pool www
www-data   953   794  0  2020 ?        00:24:14 php-fpm: pool www
www-data   954   794  0  2020 ?        00:24:29 php-fpm: pool www
...

Display specified user information

ps -u root //显示root进程用户信息

kill process

The kill command sends the specified signal to the corresponding process. Not specifying a model will send SIGTERM (15) to terminate the specified process.

The kill command can take the signal number option or not. If there is no signal number, the kill command will issue a termination signal (15). This signal can be captured by the process, allowing the process to clean up and release resources before exiting.

# 杀死进程:kill pid
kill 12345
# 强制杀死进程 kill -KILL pid
kill -KILL 123456
# 彻底杀死进程:kill -9 pid
kill -9 123456

The kill command of Linux sends a signal to the process. Kill does not mean to kill. -9 means to exit unconditionally, but it is up to the process to decide whether to exit. This is why kill -9 cannot terminate system processes and daemon processes.

Guess you like

Origin blog.csdn.net/yyuggjggg/article/details/134203508