| 0 comments ]

Basic process management tools

This document provides some basic command line process management tools for users who want a more granular view of process/memory management. Note, processes are really applications, these words will be interchanged throughout this document.

Information
This is by no means a full list of commands or switches.

Users requiring a list of switches or further explanation of command should consult the man pages.

There is a wealth of knowledge on how to use and what commands do can be obtained from www.google.com/linux

ps


The ps -ef command will display full information about each of the processes currently running.

[quickm@duvel etc]$ ps -ef | more
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 08:35 ? 00:00:00 init [5]
root 2 1 0 08:35 ? 00:00:00 [migration/0]
root 3 1 0 08:35 ? 00:00:00 [ksoftirqd/0]
root 4 1 0 08:35 ? 00:00:00 [watchdog/0]
root 5 1 0 08:35 ? 00:00:00 [events/0]
root 6 1 0 08:35 ? 00:00:00 [khelper]
root 1891 1 0 08:36 ? 00:00:00 rpc.statd
dbus 2038 1 0 08:36 ? 00:00:09 dbus-daemon --system
root 2052 1 0 08:36 ? 00:00:07 /opt/Symantec/symantec_antivirus/symcfgd
root 2068 1 0 08:36 ? 00:02:00 /opt/Symantec/symantec_antivirus/rtvscand
root 2167 1 0 08:36 ? 00:00:00 pcscd
root 2202 1 0 08:36 ? 00:00:00 automount
..... ..... .....

ps command - most active with CPU

You can use advanced ps commands to sort by a lot of things. in this example we show the top 4 (tail -4) CPU intensive processes. Note, the sed option is redundant in this example, it removes processes that are idle (0.0).

$  ps -e -o pcpu,cpu,nice,state,cputime,args --sort pcpu | sed '/^ 0.0 /d' | tail -4

0.9 - 0 S 00:03:08 /opt/ibm/lotus/notes/notes
1.0 - 0 S 00:03:24 /usr/lib/firefox-2.0.0.7/firefox-bin
1.8 - 0 S 00:06:29 /usr/sbin/wcstatusd -b
3.8 - 0 S 00:13:07 /usr/bin/Xorg :0

You can also create an alias in your login profile /home/userid/.bashrc as a short cut for a long command such as this:

alias pigs='ps -e -o pcpu,cpu,nice,state,cputime,args --sort pcpu | sed '\''/^ 0.0 /d'\''

ps command - most memory intensive

You can also sort/locate the largest memory intensive processes with ps. In the example below, Firefox is using about 50 MBs of RAM.

$ ps -e -orss=,args= | sort -b -k1,1n | tail
14712 /opt/Symantec/symantec_antivirus/rtvscand -l debug
14860 /usr/libexec/main-menu
20500 /opt/ibm/lotus/notes/taskldr
25184 /usr/bin/Xorg :0
25692 /etc/openoffice.org-2.0/program/soffice.bin -writer
51548 /usr/lib/firefox-2.0.0.7/firefox-bin
54888 /opt/ibm/lotus/notes/notes
154712 /opt/ibm/lotus/notes/framework/rcp/eclipse/plugins

You can also create an alias in your login profile /home/userid/.bashrc as a short cut for a long command such as this:

alias mempigs='echo Memory;ps -e -orss=,args= | sort -b -k1,1n | tail'

kill command


The kill command, kills a process by their PID ID. Users can force it to be killed with the -9 option but it isn't recommended.

Example: Request to kill a few processes

kill 1891 2038 2167

Example: Forcefully kill a set of processes

kill -9 1891 2038 2167

killall command


Killall allows you to kill all process with a particular name

killall firefox

top command


Top is a long time established tool for looking at processes.

top

(press h for help, it will show the most memory/cpu processes at the top of the screen.)

Example of Top running

top - 14:57:47 up  6:22,  4 users,  load average: 0.84, 1.24, 0.79
Tasks: 146 total, 1 running, 144 sleeping, 0 stopped, 1 zombie
Cpu(s): 15.0%us, 3.7%sy, 0.0%ni, 81.1%id, 0.0%wa, 0.3%hi, 0.0%si, 0.0%st
Mem: 515028k total, 470636k used, 44392k free, 3400k buffers
Swap: 1052248k total, 369892k used, 682356k free, 123828k cached

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
4116 quickm 15 0 101m 11m 7516 S 8.9 2.3 0:21.87 gnome-terminal
3487 root 15 0 67772 28m 8520 S 6.0 5.6 14:05.80 Xorg
3242 root 18 0 55348 708 576 S 1.0 0.1 7:09.95 wcstatusd
17033 quickm 16 0 2276 1060 796 S 0.7 0.2 0:08.51 top
18316 quickm 15 0 2160 1032 788 R 0.7 0.2 0:00.05 top
5460 quickm 15 0 888m 158m 45m S 0.3 31.4 3:07.63 notes2w
5514 quickm 15 0 294m 48m 28m S 0.3 9.7 3:16.83 lnotes
5858 quickm 15 0 198m 20m 12m S 0.3 4.0 0:53.34 soffice.bin
1 root 15 0 2036 564 536 S 0.0 0.1 0:00.46 init
2 root RT 0 0 0 0 S 0.0 0.0 0:00.00 migration/0
3 root 36 19 0 0 0 S 0.0 0.0 0:00.12 ksoftirqd/0
4 root RT 0 0 0 0 S 0.0 0.0 0:00.00 watchdog/0
5 root 10 -5 0 0 0 S 0.0 0.0 0:00.12 events/0
6 root 10 -5 0 0 0 S 0.0 0.0 0:00.00 khelper
7 root 11 -5 0 0 0 S 0.0 0.0 0:00.00 kthread
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND

NMON utility


The nmon tool is helpful in presenting all the important performance tuning information onone screen and dynamically updating it. The tool works on any dumb screen, telnet session, or even dial-up line. In addition, the tool is very efficient. It does not consume many CPU cycles, usually below 2%. On newer machines, CPU usage is well below 1%.

Data is displayed on the screen and updated once every two seconds using a dumb screen. However, you can easily change this interval to a longer or shorter time period. If you display the data on X-Windows via telnet and stretch the window, nmon can output a great of information all in one place.

The nmon tool can also capture the same data to a text file for later analysis and graphing for reports. The output is in a spreadsheet format (.csv)

nmon

(then for example press c and then m, to illustrate CPU and Memory)

┌nmon─11f─────────────────────Hostname=duvel────────Refresh= 2secs ───17:41.46───────┐
│ CPU Utilisation ───────────────────────────────────────────────────────────────────│
│ +-------------------------------------------------+ │
│CPU User% Sys% Wait% Idle|0 |25 |50 |75 100| │
│ 1 10.6 2.5 0.0 86.9|UUUUUs > │
│ +-------------------------------------------------+ │
│ Memory Stats ──────────────────────────────────────────────────────────────────────│
│ RAM High Low Swap │
│ Total MB 503.0 0.0 503.0 1027.6 │
│ Free MB 7.4 0.0 7.4 599.7 │
│ Free Percent 1.5% 0.0% 1.5% 58.4% │
│ MB MB MB │
│ Cached= 169.5 Active= 423.4 │
│ Buffers= 0.9 Swapcached= 118.4 Inactive = 35.0 │
│ Dirty = 0.0 Writeback = 0.0 Mapped = 95.1 │
│ Slab = 19.9 Commit_AS = 1744.7 PageTables= 6.5 │
│ Network Error Counters ────────────────────────────────────────────────────────────│
│I/F Name iErrors iDrop iOverrun iFrame oErrors oDrop oOverrun oCarrier oColls │
│ lo 0 0 0 0 0 0 0 0 0 │
│ irda0 0 0 0 0 0 0 0 0 0 │
└─────────Warning: Some Statistics may not shown─────────────────────────────────────┘

(Click here for screenshot)

Information
The interface can be bemusing for those used to more sophisticated GUI but with a little practice a very useful tool.

Try using the Keys to navigate and with the help and hint options a wealth of information can be had.

To view several things, just press the letter for them in succession (i.e. c d m ).

One way to quit is to use Cntrl + C key function.

swapon -s


Use swapon -s to view the status of the swap file. In the example below, the user has about 1GB of swap and 438MBs of it is used.

[quickm@duvel ~]$ swapon -s
Filename Type Size Used Priority
/dev/hda2 partition 1052248 438060 -1

0 comments

Post a Comment