Search This Blog

Total Pageviews

Monday 3 October 2011

Some Unix useful command

vmstat – System Activity, Hardware And System Information

The command vmstat reports information about processes, memory, paging, block IO, traps, and cpu activity.

# vmstat 3


Display Memory Utilization Slabinfo

# vmstat -m


Get Information About Active / Inactive Memory Pages

# vmstat -a

procs -----------memory---------- ---swap-- -----io---- -system-- -----cpu------
r b swpd free inact active si so bi bo in cs us sy id wa st
1 0 1032808 106792 560216 1221460 3 2 34 75 2 1 35 19 44 1 0









Proc:
-------
r: How many processes are waiting for CPU time.
b: Wait Queue - Process which are waiting for I/O (disk, network, user input,etc..)


Memory:
-----------
swpd: shows how many blocks are swapped out to disk (paged). Total Virtual memory usage.

Note: you can see the swap area configured in server using "cat proc/swaps"


free: Idle Memory
buff: Memory used as buffers, like before/after I/O operations
cache: Memory used as cache by the Operating System


Swap:
---------
si: How many blocks per second the operating system is swapping in. i.e
Memory swapped in from the disk (Read from swap area to Memory)
so: How many blocks per second the operating system is swaped Out. i.e
Memory swapped to the disk (Written to swap area and cleared from
Memory)


In Ideal condition, We like to see si and so at 0 most of the time, and we definitely don’t like to see more than 10 blocks per second.


IO:
------
bi: Blocks received from block device - Read (like a hard disk)
bo: Blocks sent to a block device - Write


System:
-------------
in: The number of interrupts per second, including the clock.
cs: The number of context switches per second.


CPU:
--------
us: percentage of cpu used for running non-kernel code. (user time, including
nice time)
sy: percentage of cpu used for running kernel code. (system time - network, IO
interrupts, etc)
id: cpu idle time in percentage.
wa: percentage of time spent by cpu for waiting to IO.











/home/anujs # ps -C oracle -o pid=
1506
8212
8214
10271
14009
14013
14015
14019
14021
14023
14025
14027
14029
14031
14033
14035
14037
14039
14041
14043
14045
14047
14125
14131
14133
14135
14150
14165
14174
14216
14467
18275
25441
27346
27614
27773
28357
28924
29032
30518
30520
30522



pgrep oracle
1506
8212
8214
10271
14009
14013
14015
14019
14021
14023
14025
14027
14029
14031
14033
14035
14037
14039
14041
14043
14045
14047
14125
14131
14133
14135
14150
14165
14174
14216
14467
18275
25441
27346
27614
27773
28357
28924
29032
30518
30520
30522


or

ps -ef|grep oracle |awk {'print $2'}

ps -ef|grep oracle|grep -v grep |awk {'print $2'}





Find Out The Top 10 Memory Consuming Process

# ps -auxf | sort -nr -k 4 | head -10


Find Out top 10 CPU Consuming Process

# ps -auxf | sort -nr -k 3 | head -10



Multiprocessor Usage

The mpstat command displays activities for each available processor, processor 0 being the first one. mpstat -P ALL to display average CPU utilization per processor:

# mpstat -P ALL




pmap – Process Memory Usage

The command pmap report memory map of a process. Use this command to find out causes of memory bottlenecks.
# pmap -d PID

To display process memory information for pid # 47394, enter:

# pmap -d 47394




ps -FAL

anujs 31253 31204 31253 0 1 64964 2256 0 Aug04 ? 00:00:09 /usr/bin/akonadi_vcard_resource --identifier akonadi_vcard_resource_0
anujs 31730 15911 31730 3 2 225930 71560 0 09:57 ? 00:09:24 /opt/google/chrome/chrome --channel=15906.2c88550.547559033 --type=renderer --lang=en-GB --force-fieldtes
anujs 31730 15911 31732 0 2 225930 71560 0 09:57 ? 00:00:01 /opt/google/chrome/chrome --channel=15906.2c88550.547559033 --type=renderer --lang=en-GB --force-fieldtes
anujs 31766 15911 31766 1 2 233705 105644 0 09:58 ? 00:03:03 /opt/google/chrome/chrome --channel=15906.2df0e00.1200530882 --type=renderer --lang=en-GB --force-fieldte
anujs 31766 15911 31768 0 2 233705 105644 0 09:58 ? 00:00:01 /opt/google/chrome/chrome --channel=15906.2df0e00.1200530882 --type=renderer --lang=en-GB --forc




# ps -Al
To turn on extra full mode (it will show command line arguments passed to process):
# ps -AlF

To See Threads ( LWP and NLWP)
# ps -AlFH


To See Threads After Processes
# ps -AlLm


Print All Process On The Server
# ps ax

# ps axu


Print A Process Tree


# ps -ejH

28359 28359 28359 pts/1 00:00:00 bash
925 925 925 pts/2 00:00:00 bash
944 944 925 pts/2 00:00:00 su
954 954 925 pts/2 00:00:00 bash
10270 10270 925 pts/2 00:00:00 sqlplus
10271 10271 10271 ? 00:00:07 oracle
2797 2797 2797 pts/3 00:00:00 bash
18761 18761 2797 pts/3 00:00:00 su
18765 18765 2797 pts/3 00:00:00 bash


# ps axjf

ps axjf
PPID PID PGID SID TTY TPGID STAT UID TIME COMMAND
0 2 0 0 ? -1 S 0 0:00 [kthreadd]
2 3 0 0 ? -1 S 0 0:00 \_ [migration/0]


10270 10271 10271 10271 ? -1 Ss 1001 0:07 | \_ oracleorcl (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq)))
28351 2797 2797 2797 pts/3 18765 Ss 1000 0:00 \_ /bin/bash
2797 18761 18761 2797 pts/3 18765 S 0 0:00 | \_ su
18761 18765 18765 2797 pts/3 18765 S+ 0 0:00 | \_ bash
28351 3260 3260 3260 pts/5 3260 Ss+ 1000 0:00 \_ /bin/bash
28351 16674 16674 16674 pts/6 16674 Ss+ 1000 0:00 \_ /bin/bash
28351 25436 25436 25436 pts/7 25436 Ss+ 1000 0:00 \_ /bin/bash
28351 16223 16223 16223 pts/10 17014 Ss 1000 0:00 \_ /bin/bash




Set Output In a User-Defined Format

# ps -eo pid,tid,class,rtprio,ni,pri,psr,pcpu,stat,wchan:14,comm
# ps axo stat,euid,ruid,tty,tpgid,sess,pgrp,ppid,pid,pcpu,comm



# ps -eopid,tt,user,fname,tmout,f,wchan

# ps -eopid,tt,user,fname,tmout,f,wchan
PID TT USER COMMAND TMOUT F WCHAN
1 ? root init - 4 5560
2 ? root kthreadd - 1 kthreadd
3 ? root migratio - 1 migration_thread
4 ? root ksoftirq - 1 run_ksoftirqd
5 ? root watchdog - 5 watchdog
6 ? root events/0 - 1 worker_thread
7 ? root netns - 1 worker_thread
8 ? root async/mg - 1 async_manager_thread
9 ? root pm - 1 worker_thread
10 ? root sync_sup - 1 bdi_sync_supers
11 ? root bdi-defa - 1 -
12 ? root kintegri - 1 worker_thread
13 ? root kblockd/ - 1 worker_thread
14 ? root kacpid - 1 worker_thread






top


Hot Key


t – Displays summary information on and off.

m – Displays memory information on and off.

A – Sorts the display by top consumers of various system resources. Useful for quick identification of performance-hungry tasks on the system.

f – Enters an interactive configuration screen for top. Helpful for setting up top for a specific task.

o – Enables you to interactively select the ordering within top.

r – Issues renice command.

k – Issues kill command.

z – Turn color/mono on or off.






# pstree

# pstree
init─┬─acpid
├─akonadi_control─┬─2*[akonadi_ical_re]
│ ├─akonadi_maildir
│ ├─akonadi_maildis
│ ├─akonadi_nepomuk───{akonadi_nepomuk}
│ ├─akonadi_vcard_r
│ ├─akonadiserver─┬─mysqld───13*[{mysqld}]
│ │ └─10*[{akonadiserver}]
│ └─3*[{akonadi_control}]
├─auditd───{auditd}
├─avahi-daemon
├─avahi-dnsconfd
├─bacula-fd───{bacula-fd}
├─chrome───3*[chrome───{chrome}]
├─console-kit-dae───63*[{console-kit-dae}]
├─cron



pmap – Process Memory Usage

The command pmap report memory map of a process. Use this command to find out causes of memory bottlenecks.

# pmap -d PID

To display process memory information for pid # 47394, enter:

# pmap -d 47394
Sample Outputs:



iostat interval count

only device
iostat -d


iostat 10 5


iostat 10 5
Linux 2.6.34.7-0.5-desktop (apt-amd-02) 03/10/11 _x86_64_

avg-cpu: %user %nice %system %iowait %steal %idle
34.96 0.03 19.54 1.20 0.00 44.35

Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn
sda 8.15 68.16 149.04 372632289 814740822
sda1 0.00 0.00 0.00 1186 34
sda2 0.36 6.97 4.61 38082698 25181888
sda3 0.60 17.08 3.85 93353181 21048118
sda4 5.69 44.12 140.58 241195000 768510782
dm-0 12.18 10.57 94.26 57778914 515299512
dm-1 4.62 33.55 46.32 183415726 253211270

No comments:

Oracle DBA

anuj blog Archive