页面“每天一个linux命令之tar命令”与“每天一命令之Ps”之间的差异
(页面间的差异)
跳到导航
跳到搜索
小 (导入1个版本) |
docker>Evan |
||
第1行: | 第1行: | ||
+ | =ps= | ||
+ | ==NAME and DESCRIPTION== | ||
+ | ps - report a snapshot of the current processes. | ||
+ | ps displays information about a selection of the active processes. | ||
− | + | Process Status ? | |
+ | ==OPTIONS== | ||
+ | <pre> | ||
+ | a 显示所有进程 all w/ tty, including other users | ||
+ | -a 显示同一终端下的所有程序 all w/ tty except session leaders | ||
+ | -A 显示所有进程 all processes | ||
+ | c 显示进程的真实名称 | ||
+ | -N 反向选择 | ||
+ | -e 等于“-A” | ||
+ | -f:显示UID,PPIP,C与STIME栏位。 | ||
+ | e 显示环境变量 | ||
+ | f 显示程序间的关系 | ||
+ | -H 显示树状结构 | ||
+ | r 显示当前终端的进程 | ||
+ | T 显示当前终端的所有程序 | ||
+ | u 指定用户的所有进程 | ||
+ | -au 显示较详细的资讯 | ||
+ | u:以用户为主的格式来显示程序状况。 | ||
+ | -aux 显示所有包含其他使用者的行程 | ||
+ | -C<命令> 列出指定命令的状况 | ||
+ | --lines<行数> 每页显示的行数 | ||
+ | --width<字符数> 每页显示的字符数 | ||
− | + | -l或l:采用详细的格式来显示程序状况。 | |
− | + | -y:配合选项"-l"使用时,不显示F(flag)栏位,并以RSS栏位取代ADDR栏位。 Do not show flags; show rss in place of addr. This option can only be used with -l. | |
+ | -C by command name <指令名称>:指定执行指令的名称,并列出该指令的程序的状况 | ||
+ | -o 用户自定义格式。 Specify user-defined format. Identical to -o and --format | ||
− | - | + | -o format |
+ | User-defined format. format is a single argument in the form of a blank-separated or | ||
+ | comma-separated list, which offers a way to specify individual output columns. The | ||
+ | recognized keywords are described in the STANDARD FORMAT SPECIFIERS section below. | ||
+ | Headers may be renamed (ps -o pid,ruser=RealUser -o comm=Command) as desired. If all | ||
+ | column headers are empty (ps -o pid= -o comm=) then the header line will not be | ||
+ | output. Column width will increase as needed for wide headers; this may be used to | ||
+ | widen up columns such as WCHAN (ps -o pid,wchan=WIDE-WCHAN-COLUMN -o comm). Explicit | ||
+ | width control (ps opid,wchan:42,cmd) is offered too. The behavior of ps -o pid=X, | ||
+ | comm=Y varies with personality; output may be one column named "X,comm=Y" or two | ||
+ | columns named "X" and "Y". Use multiple -o options when in doubt. Use the PS_FORMAT | ||
+ | environment variable to specify a default as desired; DefSysV and DefBSD are macros | ||
+ | that may be used to choose the default UNIX or BSD columns. | ||
− | + | </pre> | |
− | |||
− | [[category:ops]] [[category: | + | |
+ | ==EXAMPLES== | ||
+ | <pre> | ||
+ | ps找出消耗内存的元凶 找出最占用内存的进程 | ||
+ | ps -A --sort -rss -o comm,pmem,pcpu |uniq -c | head -10 | ||
+ | 1 COMMAND %MEM %CPU | ||
+ | 1 java 1.5 4.9 | ||
+ | 1 java 1.3 0.2 | ||
+ | |||
+ | 8 nginx 0.1 0.8 | ||
+ | |||
+ | |||
+ | ps aux|head -1;ps aux|grep -v PID|sort -rn -k +4|head | ||
+ | |||
+ | |||
+ | 查看每个FPM的内存占用:#RSS段为内存 | ||
+ | ps -ylC php-fpm --sort:rss | ||
+ | S UID PID PPID C PRI NI RSS SZ WCHAN TTY TIME CMD | ||
+ | S 0 21556 1 0 80 0 8388 75039 ep_pol ? 00:01:16 php-fpm | ||
+ | S 498 6349 21556 0 80 0 11728 811119 inet_c ? 00:01:46 php-fpm | ||
+ | S 498 21564 21556 0 80 0 14940 2053445 inet_c ? 00:04:42 php-fpm | ||
+ | S 498 21693 21556 0 80 0 14944 2054981 inet_c ? 00:04:44 php-fpm | ||
+ | S 498 21735 21556 0 80 0 14944 2054789 inet_c ? 00:04:45 php-fpm | ||
+ | |||
+ | ps命令常用用法(方便查看系统进程) | ||
+ | |||
+ | 1)ps a 显示现行终端机下的所有程序,包括其他用户的程序。 | ||
+ | 2)ps -A 显示所有进程。 | ||
+ | 3)ps c 列出程序时,显示每个程序真正的指令名称,而不包含路径,参数或常驻服务的标示。 | ||
+ | 4)ps -e 此参数的效果和指定"A"参数相同。 | ||
+ | 5)ps e 列出程序时,显示每个程序所使用的环境变量。 | ||
+ | 6)ps f 用ASCII字符显示树状结构,表达程序间的相互关系。 | ||
+ | 7)ps -H 显示树状结构,表示程序间的相互关系。 | ||
+ | 8)ps -N 显示所有的程序,除了执行ps指令终端机下的程序之外。 | ||
+ | 9)ps s 采用程序信号的格式显示程序状况。 | ||
+ | 10)ps S 列出程序时,包括已中断的子程序资料。 | ||
+ | 11)ps -t<终端机编号> 指定终端机编号,并列出属于该终端机的程序的状况。 | ||
+ | 12)ps u 以用户为主的格式来显示程序状况。 | ||
+ | 13)ps x 显示所有程序,不以终端机来区分。 | ||
+ | 最常用的方法是ps -aux,然后再利用一个管道符号导向到grep去查找特定的进程,然后再对特定的进程进行操作。 | ||
+ | |||
+ | </pre> | ||
+ | |||
+ | ==运行时间查看== | ||
+ | <pre> | ||
+ | ps -eo pid,lstart,etime,cmd | grep tomcat6 | ||
+ | 28781 Thu Oct 25 10:19:41 2018 07:13:10 | ||
+ | |||
+ | #10:19分启动的 | ||
+ | </pre> | ||
+ | |||
+ | =SEE ALSO= | ||
+ | [http://man.linuxde.net/ps ps命令] | ||
+ | |||
+ | [http://www.cnblogs.com/wangkangluo1/archive/2011/09/23/2185938.html ps命令详解] | ||
+ | |||
+ | [http://www.cnblogs.com/peida/archive/2012/12/19/2824418.html 每天一个linux命令(41):ps命令] | ||
+ | |||
+ | [http://linuxtools-rst.readthedocs.io/zh_CN/latest/tool/ps.html ps 进程查看器] | ||
+ | |||
+ | [http://jaminzhang.github.io/linux/using-ps-to-view-process-started-and-elapsed-time-in-linux/ Linux ps 命令查看进程启动及运行时间] | ||
+ | |||
+ | [http://blog.linuxchina.net/?p=2950 好玩的ps –no-heading] | ||
+ | |||
+ | [https://jaminzhang.github.io/linux/using-ps-to-view-process-started-and-elapsed-time-in-linux/ Linux ps 命令查看进程启动及运行时间] | ||
+ | |||
+ | [[category:ops]][[category:linux]] |
2018年10月25日 (四) 09:34的版本
ps
NAME and DESCRIPTION
ps - report a snapshot of the current processes. ps displays information about a selection of the active processes.
Process Status ?
OPTIONS
a 显示所有进程 all w/ tty, including other users -a 显示同一终端下的所有程序 all w/ tty except session leaders -A 显示所有进程 all processes c 显示进程的真实名称 -N 反向选择 -e 等于“-A” -f:显示UID,PPIP,C与STIME栏位。 e 显示环境变量 f 显示程序间的关系 -H 显示树状结构 r 显示当前终端的进程 T 显示当前终端的所有程序 u 指定用户的所有进程 -au 显示较详细的资讯 u:以用户为主的格式来显示程序状况。 -aux 显示所有包含其他使用者的行程 -C<命令> 列出指定命令的状况 --lines<行数> 每页显示的行数 --width<字符数> 每页显示的字符数 -l或l:采用详细的格式来显示程序状况。 -y:配合选项"-l"使用时,不显示F(flag)栏位,并以RSS栏位取代ADDR栏位。 Do not show flags; show rss in place of addr. This option can only be used with -l. -C by command name <指令名称>:指定执行指令的名称,并列出该指令的程序的状况 -o 用户自定义格式。 Specify user-defined format. Identical to -o and --format -o format User-defined format. format is a single argument in the form of a blank-separated or comma-separated list, which offers a way to specify individual output columns. The recognized keywords are described in the STANDARD FORMAT SPECIFIERS section below. Headers may be renamed (ps -o pid,ruser=RealUser -o comm=Command) as desired. If all column headers are empty (ps -o pid= -o comm=) then the header line will not be output. Column width will increase as needed for wide headers; this may be used to widen up columns such as WCHAN (ps -o pid,wchan=WIDE-WCHAN-COLUMN -o comm). Explicit width control (ps opid,wchan:42,cmd) is offered too. The behavior of ps -o pid=X, comm=Y varies with personality; output may be one column named "X,comm=Y" or two columns named "X" and "Y". Use multiple -o options when in doubt. Use the PS_FORMAT environment variable to specify a default as desired; DefSysV and DefBSD are macros that may be used to choose the default UNIX or BSD columns.
EXAMPLES
ps找出消耗内存的元凶 找出最占用内存的进程 ps -A --sort -rss -o comm,pmem,pcpu |uniq -c | head -10 1 COMMAND %MEM %CPU 1 java 1.5 4.9 1 java 1.3 0.2 8 nginx 0.1 0.8 ps aux|head -1;ps aux|grep -v PID|sort -rn -k +4|head 查看每个FPM的内存占用:#RSS段为内存 ps -ylC php-fpm --sort:rss S UID PID PPID C PRI NI RSS SZ WCHAN TTY TIME CMD S 0 21556 1 0 80 0 8388 75039 ep_pol ? 00:01:16 php-fpm S 498 6349 21556 0 80 0 11728 811119 inet_c ? 00:01:46 php-fpm S 498 21564 21556 0 80 0 14940 2053445 inet_c ? 00:04:42 php-fpm S 498 21693 21556 0 80 0 14944 2054981 inet_c ? 00:04:44 php-fpm S 498 21735 21556 0 80 0 14944 2054789 inet_c ? 00:04:45 php-fpm ps命令常用用法(方便查看系统进程) 1)ps a 显示现行终端机下的所有程序,包括其他用户的程序。 2)ps -A 显示所有进程。 3)ps c 列出程序时,显示每个程序真正的指令名称,而不包含路径,参数或常驻服务的标示。 4)ps -e 此参数的效果和指定"A"参数相同。 5)ps e 列出程序时,显示每个程序所使用的环境变量。 6)ps f 用ASCII字符显示树状结构,表达程序间的相互关系。 7)ps -H 显示树状结构,表示程序间的相互关系。 8)ps -N 显示所有的程序,除了执行ps指令终端机下的程序之外。 9)ps s 采用程序信号的格式显示程序状况。 10)ps S 列出程序时,包括已中断的子程序资料。 11)ps -t<终端机编号> 指定终端机编号,并列出属于该终端机的程序的状况。 12)ps u 以用户为主的格式来显示程序状况。 13)ps x 显示所有程序,不以终端机来区分。 最常用的方法是ps -aux,然后再利用一个管道符号导向到grep去查找特定的进程,然后再对特定的进程进行操作。
运行时间查看
ps -eo pid,lstart,etime,cmd | grep tomcat6 28781 Thu Oct 25 10:19:41 2018 07:13:10 #10:19分启动的