天天看點

linux ps-l指令詳解,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 Sroot 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   NLWPSTIME 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

1184

42

1

1

13

1

1

1

1

1

1

1

1

2

2

61

1

8

1

1088

1