Getting PID of a process
If we know the name of the application or script running , then we can get it's process id using a ps command.
ps -ef | grep <application/script name >
eg )
![]() |
| ps command |
PSTREE .
I can get the process hierarchy of a process using the pstree command .
eg)
If we run the pstree command without any pid as parameter ,we will get a process map of all the services and process running in the machine .
eg)pstree
/proc Filesystem
In linux ,everything is a file including hardware devices and running processes .The /proc filesystem has all the information about features and usage of cpu , memory , details of all the applications running in the machine .
For instance , let us take the chrome process running in my machine .
There will be a directory in /proc filesystem for each process , it will have files to store information (different properties ) about the process. The path will be like
/proc/<pid as directory name>/<files>
eg) for chrome
[prabu@dev sysctl.d]$ more /proc/2233/
attr/ comm fd/ maps ns/ personality stack uid_map
autogroup coredump_filter fdinfo/ mem numa_maps projid_map stat wchan
auxv cpuset gid_map mountinfo oom_adj root/ statm
cgroup cwd/ io mounts oom_score sched status
clear_refs environ limits mountstats oom_score_adj sessionid syscall
cmdline exe loginuid net/ pagemap smaps task/
ie)
2233 is the directory in process filesystem and the files and sub directories are below
The name of program of the process is stored in comm file
eg)
[prabu@dev sysctl.d]$ more /proc/2233/comm
chrome
The full command of the process along with path is in cmdline
eg)
[prabu@dev sysctl.d]$ more /proc/2233/cmdline
/opt/google/chrome/chrome
The userid in which it runs is in loginuid
eg)
[prabu@dev sysctl.d]$ more /proc/2233/loginuid
1000
[prabu@dev sysctl.d]$ id
uid=1000(prabu) gid=1000(prabu) groups=1000(prabu),10(wheel)
The io details like amount of data processed by the application is in io file.
eg)
[prabu@dev sysctl.d]$ more /proc/2233/io
rchar: 161425371
wchar: 111930271
syscr: 1465561
syscw: 760250
read_bytes: 327160320
write_bytes: 79355904
cancelled_write_bytes: 434176
The limits on resources that can be used by the process is in limits file .
eg)
[prabu@dev sysctl.d]$ more /proc/2233/limits
Limit Soft Limit Hard Limit Units
Max cpu time unlimited unlimited seconds
Max file size unlimited unlimited bytes
Max data size unlimited unlimited bytes
Max stack size 8388608 unlimited bytes
Max core file size 0 unlimited bytes
Max resident set unlimited unlimited bytes
Max processes 4096 14784 processes
Max open files 1024 4096 files
Max locked memory 65536 65536 bytes
Max address space unlimited unlimited bytes
Max file locks unlimited unlimited locks
Max pending signals 14784 14784 signals
Max msgqueue size 819200 819200 bytes
Max nice priority 0 0
Max realtime priority 0 0
Max realtime timeout unlimited unlimited us
The status information of process is in status ,
eg)
[prabu@dev sysctl.d]$ more /proc/2233/status
Name: chrome
State: S (sleeping)
Tgid: 2233
Ngid: 0
Pid: 2233
PPid: 1940
TracerPid: 0
Uid: 1000 1000 1000 1000
Gid: 1000 1000 1000 1000
FDSize: 512
Groups: 10 1000
VmPeak: 1773700 kB
VmSize: 1733864 kB
Similarly there are sub directories for file info in fd (fiels used by process ) and mem file which has info on memory segments allocated ,pagemap file which has information on pages related to the process.
Getting CPU details of the machine .
The details on architecture and features of cpu ,no of cores and threads can be obtained using below command.
cat /proc/cpuinfo :
eg)
[prabu@dev sysctl.d]$ cat /proc/cpuinfo |more
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 37
model name : Intel(R) Pentium(R) CPU P6200 @ 2.13GHz
stepping : 5
microcode : 0x4
cpu MHz : 2133.000
cache size : 3072 KB
physical id : 0
siblings : 2
core id : 0
cpu cores : 2
apicid : 0
initial apicid : 0
fpu : yes
fpu_exception : yes
cpuid level : 11
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx r
dtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf pni dtes64 monitor ds_cpl est tm2 ssse3 cx16 xtpr pdcm pcid
popcnt lahf_lm arat dtherm
bogomips : 4256.20
clflush size : 64
cache_alignment : 64
address sizes : 36 bits physical, 48 bits virtual
power management:
processor : 1
vendor_id : GenuineIntel
cpu family : 6
model : 37
model name : Intel(R) Pentium(R) CPU P6200 @ 2.13GHz
stepping : 5
.
.
Getting details of memory available, used and pagesize .
Details on total available memory ,used memory ,type ,size and no of pages can be obtained by below command.
cat /proc/meminfo
eg)
[prabu@dev sysctl.d]$ cat /proc/meminfo
MemTotal: 1910704 kB
MemFree: 87880 kB
MemAvailable: 378368 kB
Buffers: 0 kB
Cached: 487368 kB
SwapCached: 8168 kB
Active: 949164 kB
Inactive: 520172 kB
Active(anon): 804996 kB
Inactive(anon): 375928 kB
Active(file): 144168 kB
Inactive(file): 144244 kB
Unevictable: 0 kB
Mlocked: 0 kB
SwapTotal: 3964924 kB
SwapFree: 3934320 kB
Dirty: 332 kB
Writeback: 0 kB
AnonPages: 974848 kB
Mapped: 123884 kB
Shmem: 198956 kB
Slab: 213228 kB
SReclaimable: 171012 kB
SUnreclaim: 42216 kB
KernelStack: 3568 kB
PageTables: 32904 kB
NFS_Unstable: 0 kB
Bounce: 0 kB
WritebackTmp: 0 kB
CommitLimit: 4920276 kB
Committed_AS: 4300400 kB
VmallocTotal: 34359738367 kB
VmallocUsed: 545312 kB
VmallocChunk: 34359187208 kB
HardwareCorrupted: 0 kB
AnonHugePages: 165888 kB
HugePages_Total: 0
HugePages_Free: 0
HugePages_Rsvd: 0
HugePages_Surp: 0
Hugepagesize: 2048 kB
DirectMap4k: 67840 kB
DirectMap2M: 1888256 kB
[prabu@dev sysctl.d]$
In this list , memtotal gives total installed memory (ram) ,memavailable gives the total available memory (free memory + cached memory) that can be allocated to applications.
Hugepages_Total gives number of huge pages , hugepagesize gives the size configured in my machine which is 2Mb.
Huge pages
In general cpu allocates memory in 4KB chunks to processes called pages ,each page has an address.
But in a 64 bit system with large amount of memory ,this approach results in a very big address space make memory management inefficient.Linux supports Huge pages where we can have pages of different sizes in addition to default 4K size, most common intel cpus support pages of size 2MB , 1GB .
A single 2MB huge page has a single address ,while a 2MB of memory using normal page will have 512 page address .So using huge pages makes memory allocation and access very fast.This is very useful for memory intensive applications like database servers etc.The only con is that huge pages require contiguous blocks of memory and it is recommended to configure huge page allocation at system startup by specifying the number of pages as below by setting a kernel parameter ,
[root@dev sysctl.d]# sysctl vm.nr_hugepages
vm.nr_hugepages = 0
[root@dev sysctl.d]# sysctl -w vm.nr_hugepages=5
vm.nr_hugepages = 5
[root@dev sysctl.d]# sysctl vm.nr_hugepages
vm.nr_hugepages = 5





