ps

常用选项

-e: Select all processes. Identical to -A.
-f: does full-format listing, can be combined with many other UNIX-style options to add additional columns. When used with -L, the NLWP (number of threads) and LWP (thread ID) columns will be added.
-u: 指定用户列表
-o: 指定输出格式(指定输出字段)
-w: 宽格式输出。据说在某些系统上面(e.g. Solaris), 输出超过一定字符会被截断(笔者在几类 Linux 上测试并未出现),为了保证兼容,最好加上改选项,并且使用 ‘-www’.
Oracle Solaris man page - ps
overcoming the 80 character limitation of solaris ps

ps -e -o pid,euser,euid,ruser,ruid,egroup,egid,rgroup,rgid,cmd
ps -u xxx -o pid,ppid,user,cmd

Note
1. -o 不能和 -f 组合

案例

查看线程

ps -eLf | grep multi_category
30054    15229 10972 15229  0    5 19:52 pts/15   00:00:00 ./multi_category
30054    15229 10972 15230  0    5 19:52 pts/15   00:00:00 ./multi_category
30054    15229 10972 15231  0    5 19:52 pts/15   00:00:00 ./multi_category
30054    15229 10972 15232  0    5 19:52 pts/15   00:00:00 ./multi_category
30054    15229 10972 15233  0    5 19:52 pts/15   00:00:00 ./multi_category
30054    15250 26237 15250  0    1 19:52 pts/21   00:00:00 grep --color=auto multi_category

第2列为 pid, 第4列为线程号, multi_category 进程起了 4 个子进程,所以一共是 5 个线程。

只显示 pid, thread id, thread num, cmd

ps -L -u root -o pid,lwp,nlwp,cmd | grep gagent | grep -v grep
 6046  6046    2 ./gagent --resource-id=20151207 --centerd1=localhost:8885 --centerd2=localhost:8886 --pid-file=./gagent.pid --conf-file=./gagent.xml --tlogconf=./gagent_log.xml -D start
 6046  6049    2 ./gagent --resource-id=20151207 --centerd1=localhost:8885 --centerd2=localhost:8886 --pid-file=./gagent.pid --conf-file=./gagent.xml --tlogconf=./gagent_log.xml -D start

-u 时显示 cmd 为全名

ps -f -u user
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值