Showing posts with label pidof. Show all posts
Showing posts with label pidof. Show all posts

Wednesday, May 24, 2017

how to find number of threads in a process on linux ?

The proc pseudo file system, 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 proc pseudo file system, 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.
Threads: <N>
For example Find the pid of the google chrome and find the each process using how many Threads.

root@linuxforfreshers.com:~# ps -ef | grep chrome
root      28168 20969  1 15:45 ?        00:00:17 /opt/google/chrome/chrome

Where 28168 is pid of google chrmoe.

Or

root@linuxforfreshers.com:~# pidof chrome
28168


Example :

root@linuxforfreshers.com:~# cat /proc/28168/status
Name: chrome
State:   S (sleeping)
Tgid:    28168
Ngid:    0
Pid:      28168
PPid:    20969
TracerPid:       0
Uid:      1000    1000    1000    1000
Gid:      1000    1000    1000    1000
FDSize: 256
Groups:            4 24 27 30 46 108 124 128 1000
NStgid: 28168  12008  1
NSpid:  28168  12008  1
NSpgid:            3938    0          0
NSsid:  3938    0          0
VmPeak:          1087572 kB
VmSize:           1028908 kB
VmLck:                   0 kB
VmPin:        0 kB
VmHWM:          311332 kB
VmRSS:              212288 kB
VmData:            606664 kB
VmStk:      136 kB
VmExe:              109204 kB
VmLib:    45784 kB
VmPTE:                1676 kB
VmPMD:               620 kB
VmSwap:             8520 kB
HugetlbPages:        0 kB
Threads:          15
SigQ:    0/15451
SigPnd:            0000000000000000
ShdPnd:           0000000000000000
SigBlk: 0000000000000000
SigIgn: 0000000000001002
SigCgt: 00000001c0014efd
CapInh:            0000000000000000
CapPrm:          0000000000000000
CapEff:            0000000000000000
CapBnd:           0000003fffffffff
CapAmb:         0000000000000000
Seccomp:         2
Cpus_allowed: 3
Cpus_allowed_list:      0-1
Mems_allowed:          00000000,00000001
Mems_allowed_list:   0
voluntary_ctxt_switches:        32357
nonvoluntary_ctxt_switches:  18926

Or

root@linuxforfreshers.com:~# cat /proc/28168/status | grep Threads
Threads:          15

Method 2: Using ls command

syntax:
ls /proc/<pid>/task | wc -l

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.

Example:

root@linuxforfreshers.com:~# ls /proc/28168/task/ | wc -l
15

Method 3: Using ps command

Syntax:
ps huH p <PID_OF_U_PROCESS> | wc -l
Example :
root@linuxforfreshers.com:~# ps huH p 28168 | wc -l
15
Method 4:

Syntax: ps -eT | grep <PID_of_process> | wc -l

Example :

root@linuxforfreshers.com:~# ps -eT | grep 28168 | wc -l
15








Sunday, April 16, 2017

How to find out from which folder a process is running on linux ?

First step find out the pid of the particular process.
Example:

deb@linuxforfreshers.com:~$ pidof chrome

15499

Or

deb@linuxforfreshers.com:~$ ps -ef | grep chrome
deb     15499 15410  0 07:46 ?        00:02:33 /opt/google/chrome/chrome

Note: In above line second filed is pid number.

Method 1:
Using pwdx command.
Syntax:
pwdx  pid_number

Example:

deb@linuxforfreshers.com:~$ pwdx 15499
15499: /home/deb

Method 2:

Using lsof command.
Syntax: lsof -p PID | grep cwd

Example:

deb@linuxforfreshers.com:~$ lsof -p 15499| grep cwd
lsof: WARNING: can't stat() fuse.gvfsd-fuse file system /home/deb/.gvfs
      Output information may be incomplete.
chrome  15499 deb  cwd    DIR                8,6      4096  5767170 /home/deb

Method 3:

Using readlink command
Syntax: readlink -e /proc/PID/cwd

Example:

deb@linuxforfreshers.com:~$ readlink -e /proc/15499/cwd
/home/deb

Method 4:

Using ls command
Syntax: ls -l /proc/<PID>/cwd

Example:
deb@linuxforfreshers.com:~$ ls -l /proc/15499/cwd
lrwxrwxrwx 1 deb deb 0 Apr 13 16:21 /proc/15499/cwd -> /home/deb

Method 5:

Using ps command
Syntax : ps auxwwwe | grep process_name


It will give all the list of process running from current directory.