2014年9月1日 星期一

how many threads in a process

awk '{print $20}' /proc/pid_num/stat
or
$ /proc/pid_num/status has a Threads
or
#!/bin/bash

if [ -z $1 ];then
    echo "enter an exectue name in background, ex: chrome"
    exit
fi

target=$(ps -ef | grep -v grep | grep $1 | awk '{print $2}')

for pid in $target
do
    if [ -d /proc/$pid ]; then
        echo pid=$pid, `awk '{print $20}' /proc/$pid/stat`
    fi
done
$1: PID, Process PID
$4: Status R, S, T, ... others (LINUX PROCESSES AND SIGNALS)
$4: PPID, Father ID
$20: Thread counts

ref:
1. /proc/stat解析

沒有留言:

張貼留言