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 = ...
随机推荐
- Linux 调优方案--ulimit命令
可以用ulimit -a 来显示当前的各种用户进程限制.下面把某linux用户的最大进程数设为10000个: ulimit -u 10240 对于需要做许多 socket 连接并使它们 ...
- linux rz 乱码
Linux shell rz和sz是终端下常用的文件传输命令,rz和sz通过shell被调用,其中rz用于从启用终端的系统上传文件到目标系统(终端登录的目标系统), 这里不过多介绍这些命令,只是记录一 ...
- 说说JDK中的String.valueOf()传null的诡异处理
都说JDK的实现诡异多,今儿也算是被我踩到一个坑了. 就来说说关于String.valueOf的这个坑. public class TestString { public static void ma ...
- LR11直接对数据库访问操作方法在性能测试中的应用总结
项目背景概述 某测试项目,该项目的接口测试需要大量的订单,并且需要订单的状态是已确认客户的订单,大量的订单可以通过下单接口直接造订单数据,但下的订单要人工在后台页面处理到已确认客户的状态才可以使用这些 ...
- gridView删除提示框
实现方法: 双击GridView的OnRowDataBound事件: 在后台的GridView1_RowDataBound()方法添加代码,最后代码如下所示: protected void GridV ...
- leetcode380
class RandomizedSet { public: /** Initialize your data structure here. */ RandomizedSet() { } /** In ...
- 在Ubuntu 16.04如何安装Java使用apt-get的
转自:https://www.howtoing.com/how-to-install-java-with-apt-get-on-ubuntu-16-04/ 的Java和JVM(Java的虚拟机)是广泛 ...
- U3D中的又一个坑
using System.Collections; using System.Collections.Generic; using UnityEditor; using UnityEngine; pu ...
- 2018-2019第一学期Java助教心得
随着期末考试落下了帷幕,本学习也结束了回顾本学期的历程,对我影响最深的还是这学期很幸运的成为代老师的助教,这也是我第一次接触助教工作.刚开始的时候我心里也有很多的担心,怕自己胜任不了这份工作,但随着时 ...
- Bresenham画线算法
[Bresenham画线算法] Bresenham是一种光栅化算法.不仅可以用于画线,也可以用用画圆及其它曲线. 通过lower与upper的差,可以知道哪一个点更接近线段: 参考:<计算机图形 ...