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

  • 相关阅读:
    机器学习初篇(0.0)
    MQTT 入门介绍
    《八极拳谱》(李书文)
    Golang实战群:日志的处理机制
    【转】火山引擎 Redis 云原生实践
    【转】7000字前端性能优化总结 | 干货建议收藏
    微信小程序canvas绘制圆角边框
    【转】语义化版本 2.0.0
    Verdaccio私有 npm 服务器搭建及其配置
    【转】根据条件配置多个npm仓库
  • 原文地址:https://www.cnblogs.com/itcomputer/p/4652140.html
Copyright © 2011-2022 走看看