linux命令七ps和kill

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/uotail/article/details/88168145

PS

NAME

   ps - report a snapshot of the current processes.
   报告当前进程的快照。

SYNOPSIS

   ps [options]

DESCRIPTION

   ps displays information about a selection of the active processes.
      显示有关活动进程的选择的信息。  
      If you want a repetitive update of the selection and the displayed information, use top(1) instead.
      如果您希望对选择和显示的信息进行重复更新,请使用top(1)。

   ptions of different types may be freely mixed, but conflicts can appear.  There are some synonymous options, which are functionally identical, due to the many standards and ps implementations that this ps is compatible with.

   Note that "ps -aux" is distinct from "ps aux".  The POSIX and UNIX standards require that "ps -aux" print all processes owned by a user named "x", as well as printing all processes that would be selected by the -a option.  If
   the user named "x" does not exist, this ps may interpret the command as "ps aux" instead and print a warning.  This behavior is intended to aid in transitioning old scripts and habits.  It is fragile, subject to change, and
   thus should not be relied upon.

   By default, ps selects all processes with the same effective user ID (euid=EUID) as the current user and associated with the same terminal as the invoker.  It displays the process ID (pid=PID), the terminal associated with
   the process (tname=TTY), the cumulated CPU time in [DD-]hh:mm:ss format (time=TIME), and the executable name (ucmd=CMD).  Output is unsorted by default.
   默认情况下,ps选择与当前用户具有相同有效用户ID (euid= euid)的所有进程,并与调用程序关联到相同的终端。
   它显示进程ID (pid= pid)、与进程关联的终端(tname=TTY)、以[DD-]hh:mm:ss格式累计的CPU时间(time= time)和可执行名称(ucmd=CMD)。
   默认情况下,输出是无序的。

EXAMPLES

   To see every process on the system using standard syntax:
   使用标准语法查看系统上的每个进程:
      ps -e
      ps -ef
      ps -eF
      ps -ely

   To see every process on the system using BSD syntax:
   使用BSD语法查看系统上的每个进程:
      ps ax
      ps axu

   To print a process tree:
   打印进程树
      ps -ejH
      ps axjf

   To get info about threads:
   获取关于线程的信息:
      ps -eLf
      ps axms

   To get security info:
   获取安全信息:
      ps -eo euser,ruser,suser,fuser,f,comm,label
      ps axZ
      ps -eM

   To see every process running as root (real & effective ID) in user format:
   查看每个进程作为根(真实有效的ID)以用户格式运行:
      ps -U root -u root u

   To see every process with a user-defined format:
   以用户定义的格式查看每个进程;
      ps -eo pid,tid,class,rtprio,ni,pri,psr,pcpu,stat,wchan:14,comm
      ps axo stat,euid,ruid,tty,tpgid,sess,pgrp,ppid,pid,pcpu,comm
      ps -Ao pid,tt,user,fname,tmout,f,wchan

   Print only the process IDs of syslogd:
   只打印syslogd的进程id:
      ps -C syslogd -o pid=

   Print only the name of PID 42:
   只打印PID 42的名称:
      ps -q 42 -o comm=

在这里插入图片描述
在这里插入图片描述

SIMPLE PROCESS SELECTION简单的进程选项

   -A     Select all processes.  Identical to -e.
          选择所有进程。相同的-e。
   -e    Select all processes.  Identical to -A.

kill

NAME

kill - send a signal to a process
向进程发送一个信号

SYNOPSIS

kill [options] <pid> [...]

DESCRIPTION

The  default  signal for kill is TERM.  Use -l or -L to list available signals.
终止的默认信号是TERM。使用-l or -L来列出可用的信号。  
Particularly useful signals include HUP, INT, KILL, STOP, CONT, and 0. 
特别有用的信号包括HUP、INT、KILL、STOP、CONT和0。 
Alternate signals may be specified in three ways: -9, -SIGKILL or -KILL.
Negative PID values may be used to choose whole process groups; 
可采用负PID值选择整个过程组;
see the PGID column in ps command output.
参见ps命令输出中的PGID列。  
A PID of -1 is special; it indicates all processes except the kill process itself and init.
PID为-1是特殊的;它指示除kill进程本身和init之外的所有进程。

OPTIONS

<pid> [...]
       Send signal to every <pid> listed.
       发送信号到每一个列出。</pid>
       
 -<signal>
   -s <signal>
   --signal <signal>
          Specify the signal to be sent.  The signal can be specified by using name or number.  The behavior of signals is explained in signal(7) manual page.
       指定要发送的信号。可以使用名称或数字来指定信号。信号的行为解释在信号(7)手册页。

-l, --list [signal]
       List signal names.  This option has optional argument, which will convert signal number to signal name, or other way round.
       信号名称列表。此选项具有可选参数,可将信号编号转换为信号名称,或以其他方式转换。

-L, --table
       List signal names in a nice table.
       在一个漂亮的表中列出信号名称。

EXAMPLES

kill -9 -1
       Kill all processes you can kill.

kill -l 11
       Translate number 11 into a signal name.

kill -L
       List the available signal choices in a nice table.

kill 123 543 2341 3453
       Send the default signal, SIGTERM, to all those processes.

综合案例

  1. 发送终止信号9终止指定PID线程
    $ kill -s 9 1827
    其中-s 9 制定了传递给进程的信号是9,即强制、尽快终止进程。
    在这里插入图片描述
  2. grep查找指定线程
    把ps的查询结果通过管道给grep查找包含特定字符串的进程。管道符“|”用来隔开两个命令,管道符左边命令的输出会作为管道符右边命令的输入。
    $ ps -ef | grep firefox
  3. 使用pgrep
    $ pgrep firefox

猜你喜欢

转载自blog.csdn.net/uotail/article/details/88168145
今日推荐