Top Command In Linux | Guide To Understand Output Of ToP Command
top - Used to monitor processes and system resources#How To Run
write "top" in terminal and hit enter. First half of output shows details about processes and resource usage while lower half shows details about currently running processes. Use up and down arrow key to scroll through the list. press q to exit.#Understanding First Half of Output
*First Line
It shows current time followed by system uptime (number of days since system is running). In this example current time is 12:02:88 and system is up since 605 days and 2 hour 7 minutes.Next is number of active user sessions (1 user in this case, run who command to check active users).
Last thing is load average which gives average "load" over one, five and fifteen minutes. Here 0.09 is the average for first minutes which means cpu was 91% (1-0.09) idle over last one minute. load average of 1 means cpu was 100% utilised.
*Second Line
- This line shows statistics about the processes as explained below:
- 92 total processes (including all states of processes)
- 1 process is currently executing on the cpu (The process is in runnable state[R])
- 91 processes are in sleep state (interruptible sleep[D] - process is waiting for an even to complete, uninterruptible sleep[S] - process is waiting for an IO operation to complete)
- 0 processes are in stopped state [T]
- 0 processes are in zombie state[Z] (a child process which has exited but its data is still in memory)
*Third Line
It explains cpu statistics in %- 0.3%us - means 0.3% of cpu time is spent on executing processes in user-space
- 0.2%sy - means 0.2% of cpu time is spent on executing processes in kernel-space
- 0.0%ni - linux uses nice value to determine priority of a process. The higher the nice value means process is "nicer" to other process and itself can run later. Higher the "nice" value, lower the priority. So, here 0.0% ni means 0% of cpu time is spent on executing processes with a manually set "nice"
- 99.3%id - means that 99.9% of cpu time was spend doing nothing and it was in idle state.
- 0.0%wa - means the time cpu wait for an IO operation to complete
- 0.0%hi - This is the cpu time spent on handling hardware interrupts such as keypress of keboard
- 0.2%si - It is the cpu time spent on handling software interrupts such as divide by zero exception
- 0.0%st - st is "steal time" of cpu. It is the time spent by cpu on some other virtual machine.
*Fourth & Fifth Line
- Fourth line gives statics about RAM usage and Fifth line gives statics about Swap space usage in KB
- 8178648KB is the total RAM in the system and swap space is of 0KB which means no swap is allocated(swap space is a part of disk which act as RAM)
- 7486104KB is the RAM being used and 0KB swap is being utilised
- 692544KB is the amount of RAM available for use and 0KB of swap is available for use
- 137224KB, 435408KB is the amount of RAM and Swap being used as buffer/cache respectively. Kernel maintains a cache of frequently used disk region to save time and the amount of memory used for this is referred to as buffer/cache and it can be released by the kernel if any other process needs memory.
#Understanding Lower Half of Output
The lower half of output shows the list of processes with their details in column. We will understand what exactly each column represent:- PID - This is the process ID
- USER - It is the name of the user (mapped to User ID) who started the process
- PR - It Shows scheduling priority of the process from kernel perspective.
- NI - This field shows "Nice" value of the process
- VIRT - It is the memory consumed by the process including program's code, data stored by the process in memory and any regions of memory swapped to disk.
- RES - It is the memory consumed by the process in RAM
- SHR - It is the memory shared with other processes
- %MEM - This is the percentage of RAM used by the process
- S - This shows state of the process (possible values = [R, S, T, Z])
- %CPU - Percentage of CPU used by the process
- TIME+ - This is the total cpu time used by the process since it has started
- COMMAND - This shows the name of the process
#Managing Processes Using top
* Killing a Process - Press 'k' to kill the process, this will prompt for PID of the process to be killed then it will ask for the signal with which the process should be killed. If left blank, it kills the process gracefully with SIGTERM (15 is the code for SIGTERM).* Sorting Process List - Press following keys to sort processes:
- M - Sort by memory usage
- P - Sort by CPU usage
- N - Sort by process ID
- T - Sort by running time
* Showing List of Threads Instead of Processes - Press 'H' to list threads instead of processes.
* Showing Full Path of Processes - Press 'c' to show full path of processes and again press c to revert back
* Listing Processes Started by a Particular User - Run "top -u username", example - top -u mysql
0 comments:
Post a Comment