Skip to main content

Posts

Showing posts from May, 2017

Calculating CPU utilisation of a process inside C program?

The top program provides a dynamic real-time view of a running system.  It can display system summary information as well as a list of processes or threads currently being managed by the Linux kernel. Mostly "top" command is used for checking CPU utilisation of processes, which helps user to check which processes are CPU intensive. By default " top " command refreshes output in interval of 3 seconds. So the percentage of CPU utilisation shown is the average CPU utilisation of a process in last 3 seconds. Check the below pictures, these are the pictures captured in 3 second interval in which top refreshes its output. Note that the time is marked in red and percentage CPU utilisation field is marked in green. top output at 15:52:22 shows percentage of CPU utilisation of processes between 15:52:19 to 15:52:22. Output refreshes after 3 seconds Suppose that user wants to see percentage CPU utilization of processes in 5 min then it can run top command...

Virtual Memory(VIRT), Shared memory(SHR) and Resident memory(RES) explained

Do you know what is VIRT(virtual memory), RES(resident memory) and SHR(shared memory) really mean in top command? - Let's find out. Resident Memory - It is part of the RAM currently used by the process. RAM is logically divided into memory pages of certain size(for ex: 4096 bytes- 4 kb), memory is assigned to a process in terms of memory pages. A memory page can be associated with one process(if page is not shared) or multiple process(if a page is shared). The number of memory pages used by a process defines the resident memory(RES) it use. If you see first process(pid 25390) in top output, which is taking 933620 KB of resident memory(RES) the number of memory pages it is currently using can be calculated as:   Number of pages used = memory used(in KB)/Page size(in KB)     - Formula 1   As per this formula, first process(pid 25390) is using 233405(933620 KB/4              KB) memory pages currently. Note that page size o...