zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    Linux内核源码分析方法
    OVS处理upcall流程分析
    Linux内核源码目录结构分析
    理解OpenStack中的OpenvSwitch的几个要点
    OVS源码connmgr_run分析
    ovs-appctl 命令合集
    云计算底层技术-使用openvswitch
    OVS架构
    Open vSwitch Datapath浅析
    Openvswitch原理与代码分析(4):网络包的处理过程
  • 原文地址:https://www.cnblogs.com/itcomputer/p/4652140.html
Copyright © 2011-2022 走看看