Linux which processes using memory

How to see top processes sorted by actual memory usage?

If I understand correctly, the system has only 362 MB of available memory. My question is: How can I find out which process is consuming most of the memory? Just as background info, the system is running 64bit OpenSuse 12 .

12 Answers 12

use quick tip using top command in linux/unix

and then hit Shift + m (i.e. write a capital M ).

SORTING of task window For compatibility, this top supports most of the former top sort keys. Since this is primarily a service to former top users, these commands do not appear on any help screen. command sorted-field supported A start time (non-display) No M %MEM Yes N PID Yes P %CPU Yes T TIME+ Yes 

Or alternatively: hit Shift + f , then choose the display to order by memory usage by hitting key n then press Enter . You will see active process ordered by memory usage

hi codecowboy, perhaps you can look at commandlinefu.com/commands/view/3/… for more detailed memory used in my server i am using third party app like newrelic.com

First, repeat this mantra for a little while: «unused memory is wasted memory». The Linux kernel keeps around huge amounts of file metadata and files that were requested, until something that looks more important pushes that data out. It’s why you can run:

find /home -type f -name '*.mp3' find /home -type f -name '*.aac' 

and have the second find instance run at ridiculous speed.

Linux only leaves a little bit of memory ‘free’ to handle spikes in memory usage without too much effort.

Second, you want to find the processes that are eating all your memory; in top use the M command to sort by memory use. Feel free to ignore the VIRT column, that just tells you how much virtual memory has been allocated, not how much memory the process is using. RES reports how much memory is resident, or currently in ram (as opposed to swapped to disk or never actually allocated in the first place, despite being requested).

But, since RES will count e.g. /lib/libc.so.6 memory once for nearly every process, it isn’t exactly an awesome measure of how much memory a process is using. The SHR column reports how much memory is shared with other processes, but there is no guarantee that another process is actually sharing — it could be sharable, just no one else wants to share.

Читайте также:  Пишем sh скрипт linux

The smem tool is designed to help users better gage just how much memory should really be blamed on each individual process. It does some clever work to figure out what is really unique, what is shared, and proportionally tallies the shared memory to the processes sharing it. smem may help you understand where your memory is going better than top will, but top is an excellent first tool.

Источник

How to find which processes are taking all the memory?

Under Linux, simply press M to sort by physical memory usage (RES column). Under *BSD, run top -o res or top -o size . But htop is a lot nicer and doesn’t even consume more memory than top (however it’s not part of the basic toolset so you might not have it installed).

@Steven How can we group process with same parent? Basically firefox shows up in multiple times may be as it spawns multiple child processes. Is it possible to get combined memory usage?

If you have it installed I like htop once launching it you can press f6 , down arrow (to MEM% ), enter to sort by memory.

In Solaris the command you would need is:

This will list all processes in order of descending process image size. Note that the latter is based on memory committed to the process by the OS, not its resident physical memory usage.

There are supposedly versions of «top» available for Solaris, but these are not part of the standard installation.

Once top starts, press F to switch to the sort field screen. Choose one of the fields listed by pressing the key listed on the left; you probably want N for MEM%

If you want MEM%, pressing ‘M’ does the same stated above. ‘c’ adds command line parameters to the process list, may be informative for your problem.

This command will identify the top memory consuming processes:

ps -A --sort -rss -o pid,pmem:40,cmd:500 | head -n 6 | tr -s " " ";z" 

Doesn’t work on Solaris 9: ps: illegal option — — ps: ort is an invalid non-numeric argument for -s option ps: illegal option — r ps: s is an invalid non-numeric argument for -s option ps: unknown output format: -o pmem:40 ps: unknown output format: -o cmd:500

One nice alternative to top is htop . Check it, it is much more user friendly than regular top.

Globally: It’s always recommended to use a log analyser tool for logging history logs such as Splunk, ELK etc. So that using query language you can easily get the PIDs and its usage by CPU & memory.

AT SERVER/OS LEVEL: From inside top you can try the following:

 Press SHIFT+M ---> This will give you a process which takes more memory in descending order. 
$ ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%mem | head -10 

This will give the top 10 processes by memory usage. Also you can use vmstat utility to find the RAM usage at same time not for history.

Читайте также:  Linux ssd speed test

Источник

Linux: find out what process is using all the RAM?

Before actually asking, just to be clear: yes, I know about disk cache, and no, it is not my case 🙂 Sorry, for this preamble 🙂 I’m using CentOS 5. Every application in the system is swapping heavily, and the system is very slow. When I do free -m , here is what I got:

 total used free shared buffers cached Mem: 3952 3929 22 0 1 18 -/+ buffers/cache: 3909 42 Swap: 16383 46 16337 

So, I actually have only 42 Mb to use! As far as I understand, -/+ buffers/cache actually doesn’t count the disk cache, so I indeed only have 42 Mb, right? I thought, I might be wrong, so I tried to switch off the disk caching and it had no effect — the picture remained the same. So, I decided to find out who is using all my RAM, and I used top for that. But, apparently, it reports that no process is using my RAM. The only process in my top is MySQL, but it is using 0.1% of RAM and 400Mb of swap. Same picture when I try to run other services or applications — all go in swap, top shows that MEM is not used (0.1% maximum for any process).

top - 15:09:00 up 2:09, 2 users, load average: 0.02, 0.16, 0.11 Tasks: 112 total, 1 running, 111 sleeping, 0 stopped, 0 zombie Cpu(s): 0.0%us, 0.0%sy, 0.0%ni,100.0%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st Mem: 4046868k total, 4001368k used, 45500k free, 748k buffers Swap: 16777208k total, 68840k used, 16708368k free, 16632k cached PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ SWAP COMMAND 3214 ntp 15 0 23412 5044 3916 S 0.0 0.1 0:00.00 17m ntpd 2319 root 5 -10 12648 4460 3184 S 0.0 0.1 0:00.00 8188 iscsid 2168 root RT 0 22120 3692 2848 S 0.0 0.1 0:00.00 17m multipathd 5113 mysql 18 0 474m 2356 856 S 0.0 0.1 0:00.11 472m mysqld 4106 root 34 19 251m 1944 1360 S 0.0 0.0 0:00.11 249m yum-updatesd 4109 root 15 0 90152 1904 1772 S 0.0 0.0 0:00.18 86m sshd 5175 root 15 0 90156 1896 1772 S 0.0 0.0 0:00.02 86m sshd 

Restart doesn’t help, and, by they way is very slow, which I wouldn’t normally expect on this machine (4 cores, 4Gb RAM, RAID1). So, with that — I’m pretty sure that this is not a disk cache, who is using the RAM, because normally it should have been reduced and let other processes to use RAM, rather then go to swap. So, finally, the question is — if someone has any ideas how to find out what process is actually using the memory so heavily?

Читайте также:  What is process management in linux

Источник

Find Top Running Processes by Highest Memory and CPU Usage in Linux

I remember once reading that efficient system administrators are lazy people. The reason is not that they’re not doing their job or wasting their time – it is mostly because they have automated a good deal of their routine tasks. Thus, they don’t have to babysit their servers and can use their time to learn new technologies and always stay at the top of their game.

Part of automating your tasks, is learning how to get a script do what you would have to do yourself otherwise. Continually adding commands to your own knowledge base is just as important.

For that reason, in this article we will share a trick to find out, which processes are consuming lots of Memory and CPU utilization in Linux.

Find Linux Processes By RAM and CPU Usage

That said, let’s dive in and get started.

Check Top Processes sorted by RAM or CPU Usage in Linux

The following command will show the list of top processes ordered by RAM and CPU use in descendant form (remove the pipeline and head if you want to see the full list):

# ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%mem | head
Sample Output
PID PPID CMD %MEM %CPU 2591 2113 /usr/lib/firefox/firefox 7.3 43.5 2549 2520 /usr/lib/virtualbox/Virtual 3.4 8.2 2288 1 /home/gacanepa/.dropbox-dis 1.4 0.3 1889 1543 c:\TeamViewer\TeamViewer.ex 1.0 0.2 2113 1801 /usr/bin/cinnamon 0.9 3.5 2254 2252 python /usr/bin/linuxmint/m 0.3 0.0 2245 1801 nautilus -n 0.3 0.1 1645 1595 /usr/bin/X :0 -audit 0 -aut 0.3 2.5

Find Top Processes By RAM and CPU Usage

Brief explanation of above options used in above command.

The -o (or –format) option of ps allows you to specify the output format. A favorite of mine is to show the processes’ PIDs (pid), PPIDs (pid), the name of the executable file associated with the process (cmd), and the RAM and CPU utilization ( %mem and %cpu , respectively).

Additionally, I use —sort to sort by either %mem or %cpu . By default, the output will be sorted in ascendant form, but personally I prefer to reverse that order by adding a minus sign in front of the sort criteria.

To add other fields to the output, or change the sort criteria, refer to the OUTPUT FORMAT CONTROL section in the man page of ps command.

Summary

Monitoring process is one of the numerous tasks of a Linux server system administrator, in this tip, we looked at how you list processes on your system and sort them according to RAM and CPU use in descendant form using the ps utility.

Источник

Оцените статью
Adblock
detector