If you want to see the number of threads per process in Linux environments, there are several ways to do it.

Method One: /proc

The proc pseudo filesystem, which resides in /proc directory, is the easiest way to see the thread count of any active process. The /proc directory exports in the form of readable text files a wealth of information related to existing processes and system hardware such as CPU, interrupts, memory, disk, etc.

$ cat /proc/<pid>/status

The above command will show detailed information about the process with <pid>, which includes process state (e.g., sleeping, running), parent PID, UID, GID, the number of file descriptors used, and the number of context switches. The output also indicates the total number of threads created in a process as follows.

Threads: <N>

For example, to check the thread count of a process with PID 20571:

$ cat /proc/20571/status

The output indicates that the process has 28 threads in it.

Alternatively, you could simply count the number of directories found in /proc/<pid>/task, as shown below

$ ls /proc/<pid>/task | wc

This is because, for every thread created within a process, there is a corresponding directory created in /proc/<pid>/task, named with its thread ID. Thus the total number of directories in /proc/<pid>/task represents the number of threads in the process.

Method Two: ps

If you are an avid user of the versatile ps command, this command can also show you individual threads of a process (with "H" option). The following command will print the thread count of a process. The "h" option is needed to hide the header in the top output.

$ ps hH p <pid> | wc -l

If you want to monitor the hardware resources (CPU & memory) consumed by different threads of a process, refer to this tutorial.

How to count the number of threads in a process on Linux的更多相关文章

  1. tomcat 大并发报错 Maximum number of threads (200) created for connector with address null and port 8080

    1.INFO: Maximum number of threads (200) created for connector with address null and port 8091 说明:最大线 ...

  2. [geeksforgeeks] Count the number of occurrences in a sorted array

    Count the number of occurrences in a sorted array Given a sorted array arr[] and a number x, write a ...

  3. tomcat 大并发报错 Maximum number of threads (200) created for connector with address null and port 80

    1.INFO: Maximum number of threads (200) created for connector with address null and port 80 说明:最大线程数 ...

  4. 2017年上海金马五校程序设计竞赛:Problem C : Count the Number (模拟)

    Description Given n numbers, your task is to insert '+' or '-' in front of each number to construct ...

  5. tomcat调优方案Maximum number of threads (200) created for connector with address null and port 8091

    1.tomcat6大并发出现:INFO: Maximum number of threads (200) created for connector with address null and por ...

  6. kernel: nfsd: too many open TCP sockets, consider increasing the number of threads

    在/var/log/syslog中看到如下报错:   kernel: nfsd: too many open TCP sockets, consider increasing the number o ...

  7. Count the number of possible triangles

    From: http://www.geeksforgeeks.org/find-number-of-triangles-possible/ Given an unsorted array of pos ...

  8. OpenCV count the number of connected camera 检测连接的摄像头的数量

    有时候在项目中我们需要检测当前连接在机子上的摄像头的数量,可以通过下面的代码实现,其中连接摄像头的最大数量maxCamNum可以任意修改: /** * Count current camera num ...

  9. 1. 青蛙跳跳FrogJmp Count minimal number of jumps from position X to Y.

    青蛙跳跳: package com.code; public class Test03_1 { public int solution(int X, int Y, int D) { int res = ...

随机推荐

  1. C和指针 第三章--数据

    简要概述: <C和指针>第三章对数据进行了描述. 其中主要讲解了---变量的三个属性:作用域.链接属性和存储类型. 这三个属性决定了该变量在“什么地方可以使用”以及“该变量的值能够保持多久 ...

  2. Vue语法

    第一个Vue示例: <!DOCTYPE html> <html lang="en"> <head> <meta charset=" ...

  3. OpenLayers 3 之 地图控件(control)

    OpenLayers 3 之 地图控件(control) 地图控件(control)是指地图上比例尺,缩略图,拉近拉远的按钮,滚动控制条等控件,默认控件有三个,可以禁用. OpenLayers 3 之 ...

  4. 抛java.lang.NoClassDefFoundError: org.joda.time.ReadablePeriod错误

    转自:http://www.codeorg.cn/article/detail/qa/542 在进行activiti环境搭建时总是抛出java.lang.NoClassDefFoundError: o ...

  5. Python 位运算符 逻辑运算符 成员运算符

    位运算符 运算符 描述 实例 & 按位与运算符:参与运算的两个值,如果两个相应位都为1,则该位的结果为1,否则为0 (a & b) 输出结果12 ,二进制解释:0000 1100 | ...

  6. MySQL系统时间函数NOW(),CURRENT_TIMESTAMP(),SYSDATE()的区别

    CURRENT_TIMESTAMP是NOW的同义词,也就是说两者是相同的. SYSDATE函数返回的是执行到当前函数时的时间,而NOW返回的是执行SQL语句时的时间. 测试语句: SELECT NOW ...

  7. js 的 defer 和async属性

    添加defer延迟属性,脚本将立即下载,但会延迟到整个页面解析完毕后按顺序执行.会先于DOMContentLoaded事件执行. 添加async异步属性,脚本将立即下载,执行时不会等待其他脚本,不一定 ...

  8. ELK 日志管理系统,初次尝试记录

    简介: ELK 是一套开源的日志管理平台,主要包括三个组件,可以用于日志的收集.分析.存储和展示工作. ELK 成员:Elasticsearch .Logstash .Kibana( K4 ) ELK ...

  9. filter入门

    TestFilter.java package com.cdsxt.filter; import java.io.IOException; import javax.servlet.Filter;im ...

  10. inline-block元素出现位置错位的解决方法

    如下代码所示: <div class="container"> <div style="display: inline-block; height: 1 ...