Sunday 22 December 2013

Linux top command in brief



Linux TOP command in brief:


As almost every system admin will use ‘top’ command to monitor the system performance, there is a brief introduction about how to use ‘top’ and it’s examples:

Top can be either executed with options or interactively:

Let’s look at the options it has:
  • -c: show the command-line or program path, it is quite useful when you want to check the full command path or arguments
  • -d [interval]: the top refresh internfal
  • -H: show thread information
  • -u [uid]: shows processes only under that user
  • -p [pid]: only show that processes information.
  • When you are in the interactive mode: quite a few tips:
  • Sorting with -O (Uppercase Letter ‘O’). then choose the field you want to sort.
  • Kill running process with argument ‘k’ then enter the [PID]
  • Save Top Command Results [shift+w]
  • Wrote configuration to '/root/.toprc
  • Use ‘f’ option to change the displayed fields 

How to analyse the Output:


line-1:  current time and length of time since last boot, total number of users,system load avg over the last 1, 5 and 15 minutes
line-2: shows total tasks or threads, depending on the state of the Threads-mode toggle. That total is further classified as: running; sleeping; stopped; zombie
line-3: shows CPU state percentages based on the interval since the last refresh. Where two labels are shown below, those for more recent kernel versions are shown first:
  •  us: time running un-niced user processes
  •  sy : time running kernel processes
  •  ni, nice : time running niced user processes
  •  wa, IO-wait : time waiting for I/O completion
  •  hi : time spent servicing hardware interrupts
  • si : time spent servicing software interrupts
  • st : time stolen from this vm by the hypervisor

line-4 reflects physical memory, classified as: total, used, free, buffers
line-5 reflects virtual memory(swap), classified as: total, used, free, cached

column fields:
PID -- Process Id. The task's unique process ID
USER -- User Name. The effective user name of the task's owner.
PR -- Priority. The scheduling priority of the task. If you see 'rt' in this field, it means the task is running under 'real time' scheduling priority.
VIRT -- Virtual Memory Size (KiB). The total amount of virtual memory used by the task. It includes all code, data and shared libraries plus pages that have been swapped out and pages that have been mapped but not used.
RES -- Resident Memory Size (KiB). The non-swapped physical memory a task has used.
SHR -- Shared Memory Size (KiB). The amount of shared memory available to a task, not all of which is typically resident
S-Process Status. The status of the task which can be one of:
  • 'D' = uninterruptible sleep
  • 'R' = running
  • 'S' = sleeping
  • 'T' = traced or stopped
  • 'Z' = zombie
TIME -- CPU Time. Total CPU time the task has used since it started.
%CPU -- CPU Usage. The task's share of the elapsed CPU time since the last screen update, expressed as a percentage of total CPU time
%MEM -- Memory Usage (RES). A task's currently used share of available physical memory.
COMMAND -- Command Name or Command Line.

yes. that's true, if you need to understand 'top', you should have deep understanding of how linux kernel works

No comments:

Post a Comment