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 = ...
随机推荐
- Mac Terminal终端光标的快捷键操作
2016年08月18日 18:26:06 阅读数:4217 Mac Terminal终端和linux上终端光标的快捷键操作是一样的,都是来自Emacs这个神级的编辑器,由于我以前vim用的多,没怎么用 ...
- 在线pubmed
ESearch(文本搜索) eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi http://eutils.ncbi.nlm.nih.gov/entr ...
- @RestController的方法中 路径参数带.(点号)配置
如下面这种//http://localhost:8080/api/v1/user/info/email/test@163.com @RequestMapping(value = "/info ...
- python 3389爆破机
前言: = =上学后的第一个星期假期,写了个3389爆破器 - 0x01 准备: hydra 钟馗之眼API 0x02代码: import optparse import os import requ ...
- 自己动手实现XXX系列
前记: 最近看了rongjun的一片文章:自己动手实现jdk代理类.按照上面的例子敲完才发现,JDK动态代理 实现底层原来如此简单,只是大量的使用了反射,类编译,类加载一些常规的东西 而且本质也是如实 ...
- day9-IO心得
Gevent协程 Select\Poll\Epoll异步IO与事件驱动 Python连接Mysql数据库操作 RabbitMQ队列 Redis\Memcached缓存 Paramiko SSH Tws ...
- vue组件重新加载(刷新)
vue组件重新加载(刷新) 第一种方法:利用v-if控制router-view,在根组件APP.vue中实现一个刷新方法 <template> <router-view v-if=& ...
- subprocess in python3.5
subprocess 该子模块允许你创建新的流程,连接到它们的输入/输出/错误管道,并获取他们的返回值.该模块打算替换多个旧的模块和功能:os.system 和 os.spawn * 使用sub ...
- Mysql在spring中jdbc.properties连接配置
############################## mysql的数据源 ############################## jdbc.driver=com.mysql.jdbc.D ...
- 多线程 同步对象 event 简单实例 &进程间通信
多线程 同步对象event import threading,time class Boss(threading.Thread): def run(self): print("BOSS:今晚 ...