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. News Master-DC and Marvel they are super heroes mother

    News Master Good evening everyone,I’m Jason,I’m glad to be news master to share something, Tonight I ...

  2. pickle示例

    my_pickle.py---------------------- #!/usr/bin/env python # encoding: utf-8  # Date: 2018/6/3import p ...

  3. java 堆、栈、常量池等

    寄存器:我们在程序中无法控制 栈:存放基本类型的数据和对象的引用,但对象本身不存放在栈中,而是存放在堆中 堆:存放用new产生的数据 静态域:存放在对象中用static定义的静态成员 常量池:存放常量 ...

  4. Rpm打包程序

    1.Rpm打包程序1.1为什么要使用rpm打包1.编译安装软件,优点是可以定制化安装目录.按需开启功能等,缺点是需要查找并实验出适合的编译参数,诸如MySQL之类的软件编译耗时过长.2.yum安装软件 ...

  5. K老在拿图灵奖时的发言:Computer Programming as an Art

    很多话说得很透彻,把一些觉比较精彩的摘抄一下. ... It seems to me that if the authors I studied were writing today, they wo ...

  6. 使用C#书写SQLite数据库增删改查语句(以及插入byte[]时遇到的问题总结)

    在没有使用SQLite这种轻量级的数据库之前,只使用过Sqlserver2008进行数据的增删改查,公司使用的是大型的ORACLE数据库,还没有真正的会使用它.那时候觉得数据库很庞大,然而遇到SQLi ...

  7. 「小程序JAVA实战」小程序上传短视频(46)

    转自:https://idig8.com/2018/09/14/xiaochengxujavashizhanxiaochengxushangchuanduanshipin45/ 个人信息:用户上传短视 ...

  8. grideh SelectedRows Bookmark

    VCL grideh 选中多行 TBookmark.Bookmark.GotoBookmark TBookmark bm= DataSet->GetBookmark(); DataSet-> ...

  9. Agile1001社区10月份活动:一张图解读企业级产品思维

    活动信息 主题:一张图解读企业级产品思维 地点:北京市海淀区苏州街3号大恒科技大厦南座4层 时间: 2017-10-15 14:00 - 17:00 报名链接:http://www.hdb.com/p ...

  10. 验证码及密码加密在java中使用

    package com.huawei.filter; import java.io.IOException; import javax.servlet.Filter;import javax.serv ...