How to count the number of threads in a process on Linux
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.
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:
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的更多相关文章
- 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 说明:最大线 ...
- [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 ...
- 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 说明:最大线程数 ...
- 2017年上海金马五校程序设计竞赛:Problem C : Count the Number (模拟)
Description Given n numbers, your task is to insert '+' or '-' in front of each number to construct ...
- 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 ...
- 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 ...
- Count the number of possible triangles
From: http://www.geeksforgeeks.org/find-number-of-triangles-possible/ Given an unsorted array of pos ...
- OpenCV count the number of connected camera 检测连接的摄像头的数量
有时候在项目中我们需要检测当前连接在机子上的摄像头的数量,可以通过下面的代码实现,其中连接摄像头的最大数量maxCamNum可以任意修改: /** * Count current camera num ...
- 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 = ...
随机推荐
- C++ 11 自旋锁
// Spin lock implementation. // BasicLockable. // Async-signal safe. // unlock() "synchronizes ...
- C++模板类练习题
题目说明: 编写一个程序,使用类模板对数组元素进行排序,倒置.查找和求和 具有对数组元素进行排序,倒置.查找和求和功能, 然后产生类型实参分别为int型和double型的两个模板类, 分别对整型数组与 ...
- python覆盖率统计
啦啦啦,最近在跟离线脚本写自动化,真麻烦呀~ 离线任务是python写的,自动化写完了,就得统计覆盖率了. coverage.py是一个用来统计python程序代码覆盖率的工具.网上有很多资料,使用起 ...
- 代做JSP课程设计,毕业设计
代做JSP课程设计,毕业设计,大家都是学生,绝对靠谱,有意者加我Q 279283855
- 微信浏览器清缓存、cookie等
微信浏览器访问:http://debugx5.qq.com
- 新版Eclipse使用遇到的问题总结
1.SDK下载很慢. 配置SDK代理,速度像飞一样.建议先把20-24下完,不然后面遇到很多问题. 2.support-v7的问题 例如res\values\styles.xml:4: error: ...
- sql中经度维度计算距离
------------------------------------------创建一个方法---------------------------------------------------- ...
- Python面向对象相关知识1
1. python是动态的语言,这样在使用类的时候,类的属性就可以随意的添加,但是这样在实际开发中有一定的缺陷,所以,可以在类中定义一个特殊的__init__()方法,当创建实例时,__init__( ...
- django-rest-swagger
前提工作 pip3 install --user django>=2.0.0 pip3 install --user django-rest-swagger 安装完成之后,创建一个django项 ...
- java使用POI写Excel文件
参考地址:http://www.cnblogs.com/xwdreamer/archive/2011/07/20/2296975.html 1 jar包 网上下载 2 源代码 package zjr. ...