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. Jquery 页面初始化常用的三种方法以及Jquery 发送ajax 请求

    第一种 $(document).ready(function(){ //文档就绪事件 }); 第二种是第一种的简略写法,效果上和第一种是等效的. $(function(){ //文档加载事件,整个文档 ...

  2. yum ftp本地源

    一. 准备工作1. 安装系统centos7.32. 环境 10.10.10.14 controller-1 10.10.10.15 computer-1 3. 在14主机上安装FTP服务yum ins ...

  3. 在Ubuntu 16.04如何安装Java使用apt-get的

    转自:https://www.howtoing.com/how-to-install-java-with-apt-get-on-ubuntu-16-04/ 的Java和JVM(Java的虚拟机)是广泛 ...

  4. 表单验证常用的JS正则表达式

    在表单验证中,使用正则表达式来验证正确与否是一个很频繁的操作,本文收集整理了15个常用的javaScript正则表达式,其中包括用户名.密码强度.整数.数字.电子邮件地址(Email).手机号码.身份 ...

  5. Python的输入输出

    一:Python2.x版本下的输入输出 Python2.x 下的输入 1)raw_input 格式:result = raw_input("提示信息")功能:1)会等待用户输入内容 ...

  6. 不可能的工作:在FBX模型导入脚本中生成模型的预置体

    #if UNITY_EDITOR using System.Collections; using System.Collections.Generic; using System.IO; using ...

  7. MySQL数据库篇之库的增删改查

    主要内容: 一.系统数据库介绍 二.创建数据库 三.数据库增删改查 四.MySQL添加注释 1️⃣ 系统数据库介绍 1.初识sql语句 有了mysql这个数据库软件,就可以将程序员从对数据的管理中解脱 ...

  8. sha1sum校验下载的文件

    [root@mhc1 test]# sha1sum Percona-XtraBackup-2.4.8-r97330f7-jessie-x86_64-bundle.tara9c6b1c7cb3bf98b ...

  9. js闭包的定义

    通过函数字面量创建的函数对象包含一个连接到外部上下文的连接,这叫做闭包. 还有一种定义:函数可以访问它被创建时所处的上下文环境,叫做闭包.

  10. Level Of Detail

    [Level Of Detail] LOD0离摄像机最近,LODN离摄像机最远.LOD Group组件的用法是,将此组件挂在根节点上,然后每一个LOD挂同样多的Renderer(通常是子对象). At ...