ps命令实用方法.ps -l ps -L详解

 

一、统计sleep状态的进程.

c233 plugins # ps -elf|head -1
F S UID     PID   PPID C PRI   NI       ADDR   SZ    WCHAN    STIME TTY TIME     CMD
4 S root 28149  4204    0 80     0             -       16283    poll_s       Jul05 ? 00:00:00   sshd: root

c233 plugins #  ps -efl|awk '$2~/S/{print $0}'|wc -l                     //-l              long format
73
解释===>
(1)F列.

PROCESS FLAGS
The sum of these values is displayed in the "F" column, which is provided by the flags output specifier.
1 forked but didn't exec
4 used super-user privileges

(1)S列.

D Uninterruptible sleep (usually IO)
R Running or runnable (on run queue)
S Interruptible sleep (waiting for an event to complete)
T Stopped, either by a job control signal or because it is being traced.
W paging (not valid since the 2.6.xx kernel)
X dead (should never be seen)
Z Defunct ("zombie") process, terminated but not reaped by its parent.

(3)C列.C     pcpu         cpu utilization

(4)

command    COMMAND  see args. (alias args, cmd).

sz                    SZ       size in physical pages of the core image of the process. This
includes text, data, and stack space. Device mappings are currently
excluded; this is subject to change. See vsz and rss.

(5)WCHAN列.

wchan           WCHAN     name of the kernel function in which the process is sleeping,
a "-" if the process is running, or a "*" if the process is
multi-threaded and ps is not displaying threads.

 

二、统计当前运行的线程总数."-L"

c233 plugins # ps -eLf|grep -v $$|wc -l                                  //-L              Show threads, possibly with LWP and NLWP columns

646

c233 plugins # ps -eLf|grep -v $$|tail

UID        PID    PPID    LWP    C   NLWP   STIME TTY   TIME     CMD

root   23678    1    688    0    36      Jul01 ? 00:00:06   /usr/sbin/nscd
root   23678    1    689    0    36      Jul01 ? 00:00:06   /usr/sbin/nscd
root   23678    1    690    0    36      Jul01 ? 00:00:06   /usr/sbin/nscd
root   23678    1    691    0    36      Jul01 ? 00:00:06     /usr/sbin/nscd
root   23678    1    692    0    36      Jul01 ? 00:00:06     /usr/sbin/nscd
root   23678    1    693    0    36      Jul01 ? 00:00:06     /usr/sbin/nscd
root   23678    1    694    0    36      Jul01 ? 00:00:06     /usr/sbin/nscd
root   23678    1    695    0    36      Jul01 ? 00:00:06     /usr/sbin/nscd
root   23678    1    696    0    36    Jul01 ? 00:00:06     /usr/sbin/nscd
root   28149    4204 28149   0    1        Jul05 ? 00:00:00     sshd: root

NLWP (number of threads)

LWP (thread ID)

c233 plugins # ps -ef|grep nscd
root 23678 1 0 Jun30 ? 00:15:32 /usr/sbin/nscd

三、Linux下查看某个进程的线程数量.

1.根据进程号进行查询:

# pstree -p 进程号      //-p pid

# top -Hp 进程号        //-H : Threads toggle

2.根据进程名字进行查询:

# pstree -p `ps -e | grep sshd | awk '{print $1}'`

# pstree -p `ps -e | grep sshd | awk '{print $1}'` | wc -l

四、统计正在sleeop的线程总数.

d231 ~ # for i in `ps aux|awk '$8~/S/{print $2}'`;do             //如何让其累加??如何查看正在运行的线程????
> m=`pstree -p $i|wc -l`
> echo $m
> done
No such user name: PID
0
1184
42
1
1
13
1
1
1
1
1
1
1
1
2
2
0
0
61
1
8
1
1088
1

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值