用ps 查看线程状态

ps -eLo pid,tid,class,rtprio,ni,pri,psr,pcpu,pmem,stat,wchan:30,comm

线程相关选项:

THREAD DISPLAY
H Show threads as if they were processes

-L Show threads, possibly with LWP and NLWP columns

-T Show threads, possibly with SPID column

m Show threads after processes

-m Show threads after processes

状态的打印项含义:

PROCESS STATE CODES
       Here are the different values that the s, stat and state output specifiers (header "STAT" or "S") will display to describe the state of a
       process.
       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.

       For BSD formats and when the stat keyword is used, additional characters may be displayed:
       <    high-priority (not nice to other users)
       N    low-priority (nice to other users)
       L    has pages locked into memory (for real-time and custom IO)
       s    is a session leader
       l    is multi-threaded (using CLONE_THREAD, like NPTL pthreads do)
       +    is in the foreground process group

 

-o 选项指定打印的项:

OBSOLETE SORT KEYS
       These keys are used by the BSD O option (when it is used for sorting). The GNU --sort option doesn’t use these keys, but the specifiers
       described below in the STANDARD FORMAT SPECIFIERS section. Note that the values used in sorting are the internal values ps uses and not the
       "cooked" values used in some of the output format fields (e.g. sorting on tty will sort into device number, not according to the terminal name
       displayed). Pipe ps output into the sort(1) command if you want to sort the cooked values.

       KEY   LONG         DESCRIPTION
       c     cmd          simple name of executable
       C     pcpu         cpu utilization
       f     flags        flags as in long format F field
       g     pgrp         process group ID
       G     tpgid        controlling tty process group ID
       j     cutime       cumulative user time
       J     cstime       cumulative system time
       k     utime        user time
       m     min_flt      number of minor page faults
       M     maj_flt      number of major page faults
       n     cmin_flt     cumulative minor page faults
       N     cmaj_flt     cumulative major page faults
       o     session      session ID
       p     pid          process ID
       P     ppid         parent process ID
       r     rss          resident set size
       R     resident     resident pages
       s     size         memory size in kilobytes
       S     share        amount of shared pages
       t     tty          the device number of the controlling tty
       T     start_time   time process was started
       U     uid          user ID number
       u     user         user name
       v     vsize        total VM size in kB
       y     priority     kernel scheduling priority

 

其他,man ps可以查看。

posted on 2014-05-23 15:03 过雁 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/zwCHAN/p/3747762.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 在 Linux 中可以使用 ps 命令查看线状态,例如: ``` ps -eLf ``` 该命令会显示所有进程和它们的线程,包括进程 ID、线程 ID、状态等信息。 也可以使用 top 命令,在 top 命令中使用 H 来查看线程,例如: ``` top -H ``` 或者使用 pstree 命令可以以树状图的形式显示进程,例如: ``` pstree -p <pid> ``` 或者使用 htop 这个工具,htop 可以在命令行中实时显示系统的进程和线状态。 ### 回答2: 在Linux系统中,我们可以使用一些命令来查看线程的状态。下面我将介绍一些常用的命令和使用方法。 1. top命令 top 命令是查看进程状态的常用命令,我们可以通过设置它的参数来查看线程的状态。执行以下命令: top -H 其中-H参数是指显示线程列表,而不是进程列表。通过这个命令,我们可以看到每个线程的ID、CPU 使用率、内存使用情况等信息。按下"Shift+H"可以切换线程和进程的显示。 2. ps命令 ps 命令也是常用的查看进程状态的命令,我们可以使用它来查看特定进程的线状态。执行以下命令: ps -eLf 其中-e参数表示查看所有进程,-L参数表示查看线程,-f参数表示显示进程详细信息。我们可以看到每个线程的ID、状态、优先级、CPU使用率等信息。 3. lsof命令 lsof 命令可以查看打开文件和网络连接的进程和线程,我们可以通过他来查看指定进程的线状态。执行以下命令: lsof -p {pid} | grep -i thread 其中{pid}是指要查看的进程ID,我们可以看到该进程下的所有线程信息。 4. gdb命令 gdb 命令是一个强大的调试工具,我们可以通过它来查看正在运行的进程的线状态。执行以下命令: gdb -p {pid} 其中{pid}是指要查看的进程ID。然后输入命令bt full可以查看进程中所有线程的状态信息,其中包括线程ID、进程状态、堆栈信息等。 总之,Linux系统提供了很多命令用于查看线状态,我们可以根据不同的情况选择不同的命令。熟练掌握这些命令可以更好地理解进程和线程的运行机制,并帮助我们更好地管理和优化系统性能。 ### 回答3: 在Linux中,我们可以使用多种工具来查看和管理线程的状态,以下是几种较常用的方法: 1. top命令:top命令是一种监视系统资源和进程状况的命令。当需要查看线状态时,可以在top命令中按下“H”键,它会显示出所有线程的信息。在top命令中,可以查看线程的ID、CPU占用率、内存占用率、优先级等信息。 2. ps命令:ps命令是一种常见的进程管理命令。在Linux中,我们可以使用“ps -eLf”命令来查看所有线程的信息。 ps命令会列出所有进程及其对应的线程,并显示出线程的状态、优先级、CPU占用率等信息。 3. htop命令:htop命令是一个类似于top命令的进程监控工具,但是它可以更清晰地显示线程和进程的信息。使用htop命令可以方便地查看线程的状态,并可以通过交互式界面来对进程和线程进行操作。 4. perf命令:perf命令是Linux内核性能分析工具。它可以用来监测CPU性能事件、跟踪系统调用、查看调用图等。在性能分析中,perf命令可以帮助我们查找程序性能瓶颈以及优化程序。 5. gdb命令:gdb命令是一个强大的调试工具,我们可以使用它来查看线程的状态。使用gdb命令时,我们需要首先编译程序时加上“-g”选项,然后使用gdb启动程序,并在调试模式下查看线程的状态。gdb命令可以查看线程的调用栈、寄存器信息、变量值等。 总之,Linux提供了多种工具来查看线状态,我们可以根据实际情况选择合适的工具进行操作。在日常工作中,及时了解线程的状态对于调试程序和优化性能都是非常重要的。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值