Is your Linux system running sluggishly? Maybe there are processes that are heavily consuming the use of the CPU, and also the memory.
There are several command tools that can be used to identify the culprits. Let's take a look at our old friend - ps - to see how it can display the memory and cpu consumption, in a sorted order.
$ ps aux --sort=-%-cpu | more
- Notice how the processes are sorted in an ascending order, based on the most CPU consumption
We can glean similar output for memory consumption, using the following command:
$ ps aux --sort=%-mem | more
Nice..Thanks for sharing..!
@Trevor Another important tool in the arsenal of a Linux admin.
I think the command is : ps aux --sort=-%cpu | more &
ps aux --sort=-%mem | more
Please note that %CPU value reported by ps is calculated by taking the total CPU time a process has accumulated (the sum of user time and system time) and dividing it by the total time the process has been running since it started. In contrast to tools like top, which display CPU utilization in near real-time, ps presents an average CPU usage over the entire lifespan of the process.
So, if you need real time data, top is your goto tool.
Same way -
The %MEM value indicates the proportion of a process's Resident Set Size (RSS) relative to the system's total RAM.
The Resident Set Size (RSS) represents the actual physical memory pages a process is currently occupying in RAM. This excludes any memory that has been swapped out to disk or file data that hasn't been explicitly mapped into the process's address space.
So, when multiple processes use the same shared libraries or executable files, the memory pages containing this shared code (text pages) are counted towards the memory usage of each individual process. As a result, if many instances of the same program are running, the sum of their %MEM values can exceed 100% of the total physical RAM available.
Note : On Linux systems, the ps command operates by examining the /proc/[pid]/stat file for each running process. When a system hosts a large number of processes, this iterative traversal of numerous files can lead to a measurable increase in both CPU utilization and I/O overhead.
Another ps command combination to sort and list top 5 CPU and MEM consuming processes :
ps -Ao user,uid,comm,pid,pcpu,tty --sort=-pcpu | head -n 6
ps -Ao user,uid,comm,pid,pmem,tty --sort=-pmem | head -n 6
Red Hat
Learning Community
A collaborative learning environment, enabling open source skill development.