Tech Junkie Blog - Real World Tutorials, Happy Coding!: Linux Performance: procps-ng Commands, free, pmap, pwdx

Monday, April 4, 2022

Linux Performance: procps-ng Commands, free, pmap, pwdx

 In this post we are going to look at the procps-ng package commands to get some performance related information on our Linux system.

The first command we are going to look at is the free command, which shows the free memory available

[root@cent7 jhuynh]# free
              total        used        free      shared  buff/cache   available
Mem:        1882072      754028      404848       33544      723196      942276
Swap:        978940           0      978940

We can use the free command with the -m option to show the free memory in megabytes

[root@cent7 jhuynh]# free -m
              total        used        free      shared  buff/cache   available
Mem:           1837         734         397          32         706         922
Swap:           955           0         955

Or free -g for gigabytes

[root@cent7 jhuynh]# free -g
              total        used        free      shared  buff/cache   available
Mem:              1           0           0           0           0           0
Swap:             0           0           0

The next command we are going to look at is the pmap command, let's grab a process id for this one with the ps -l  command

[root@cent7 jhuynh]# ps -l
F S   UID   PID  PPID  C PRI  NI ADDR SZ WCHAN  TTY          TIME CMD
4 S     0  3358  3315  0  80   0 - 68658 poll_s pts/0    00:00:00 sudo
4 S     0  3365  3358  0  80   0 - 58056 do_wai pts/0    00:00:00 su
4 S     0  3368  3365  0  80   0 - 29107 do_wai pts/0    00:00:00 bash
0 R     0  4238  3368  0  80   0 - 38332 -      pts/0    00:00:00 ps

Let's run the pmap command on the bash process, the pmap command displays the memory map of a process, besides the memory usage it's nice to see the shared libraries used for the process

[root@cent7 jhuynh]# pmap 3368
3368:   bash
0000000000400000    888K r-x-- bash
00000000006dd000      4K r---- bash
00000000006de000     36K rw--- bash
00000000006e7000     24K rw---   [ anon ]
00000000021b3000   1144K rw---   [ anon ]
00007f53b0616000     48K r-x-- libnss_files-2.17.so
00007f53b0622000   2044K ----- libnss_files-2.17.so
00007f53b0821000      4K r---- libnss_files-2.17.so
00007f53b0822000      4K rw--- libnss_files-2.17.so

Another useful command is the pwdx command, this command finds the home working directory of a process.  So if we run the command pwdx 3368 we will find out what the home working directory of the bash shell is

[root@cent7 jhuynh]# pwdx 3368
3368: /home/jhuynh
[root@cent7 jhuynh]# ps -l
F S   UID   PID  PPID  C PRI  NI ADDR SZ WCHAN  TTY          TIME CMD
4 S     0  3358  3315  0  80   0 - 68658 poll_s pts/0    00:00:00 sudo
4 S     0  3365  3358  0  80   0 - 58056 do_wai pts/0    00:00:00 su
4 S     0  3368  3365  0  80   0 - 29107 do_wai pts/0    00:00:00 bash
0 R     0  4345  3368  0  80   0 - 38332 -      pts/0    00:00:00 ps


1 comment:

Search This Blog