Skip to main content
Share Your Experience: Take the 2024 Developer Survey
199 votes

How to monitor CPU/memory usage of a single process?

Procpath 2020 update (Linux/procfs-only). Returning to the problem of process analysis frequently enough and not being satisfied with the solutions I described below originally, I decided to write my ...
saaj's user avatar
  • 2,458
73 votes
Accepted

What do the "buff/cache" and "avail mem" fields in top mean?

top’s manpage doesn’t describe the fields, but free’s does: buffers Memory used by kernel buffers (Buffers in /proc/meminfo) cache Memory used by the page cache and slabs (Cached and SReclaimable in /...
Stephen Kitt's user avatar
55 votes

How to view a specific process in top

top -p `pgrep -d "," java` Explanation: top -p pid1,pid2: show multiple process information, the pid should be separated by , pgrep -d "," java: print the pids of all java program, the pids are ...
Mingjiang Shi's user avatar
45 votes

Linux "top" command: What are us, sy, ni, id, wa, hi, si and st (for CPU usage)?

us - Time spent in user space sy - Time spent in kernel space ni - Time spent running niced user processes (User defined priority) id - Time spent in idle operations wa - Time spent on waiting on IO ...
Simon Rigét's user avatar
44 votes

How to view a specific process in top

In OpenBSD top, just press g and enter the command name you'd like to filter on. In top on e.g. Ubuntu, press o and enter e.g. COMMAND=chrome to only show entries from the COMMAND column that are ...
Kusalananda's user avatar
  • 337k
37 votes
Accepted

"buff/cache" is very high, how I can free it?

You don't need to free "buff/cache". "buff/cache" is memory that Linux uses for disk caching, and that will be freed whenever applications require it. So you don't have to worry if ...
dr_'s user avatar
  • 29.9k
37 votes
Accepted

When redirecting top to a file, why does cat command on that file display output of multiple top attempts?

Some top implementation (e.g. on OpenBSD, but presumably on some Linux systems too) detects whether its output is going to the terminal or to something that isn't a terminal (to a pipe or to a file) ...
Kusalananda's user avatar
  • 337k
34 votes
Accepted

clear the filters added in `top`

I guess you found this out already, but just for the sake of others running into this question when googling, pressing = should reset all filters added with o when running top.
Rado's user avatar
  • 456
34 votes
Accepted

How does a CPU know there is IO pending?

The CPU doesn’t know any of this, the task scheduler does. The definition you quote is somewhat misleading; the current procfs(5) manpage has a more accurate definition, with caveats: iowait (since ...
Stephen Kitt's user avatar
33 votes
Accepted

Why does 'top' fail to run via 'xargs'?

Turns out that there is a special option --open-tty in xargs for interactive applications like top. From man xargs: -o, --open-tty Reopen stdin as /dev/tty in the child process before ...
ks1322's user avatar
  • 1,656
31 votes

top / htop; group process by command

Pressing H in htop group the processes by the main thread (command), actually it toggles the threads visibility.
BG Adrian's user avatar
  • 443
27 votes

What do the "buff/cache" and "avail mem" fields in top mean?

Just to clarify a bit, buffers refers to data that is being written -- that memory cannot be reclaimed until the write is complete. Cache refers to data that has been read -- it is kept around in ...
WallStProg's user avatar
26 votes
Accepted

How do I get "top" command to wrap its output?

top -bcn1 -w512 The elegant solution is to use the option -w [number]. According to the man page, the maximum width is 512 characters, so you will need a different solution for anything exceeding ...
boof's user avatar
  • 404
25 votes
Accepted

How is the "load average" interpreted in "top" output? Is it the same for all distributions?

The CPU load is the length of the run queue, i.e. the length of the queue of processes waiting to be run. The uptime command may be used to see the average length of the run queue over the last ...
Kusalananda's user avatar
  • 337k
24 votes
Accepted

Is there an equivalent to top but for network I/O?

There's ntop and nethogs. And on Linux there's iotop for io.
Henrik supports the community's user avatar
22 votes

Differences and relations between VIRT and USED in output of top?

RES is the amount of RAM currently used by the process. This value can vary because memory pages might be swapped in or out. It might even be 0 for a process that has been sleeping for a long time, e....
jlliagre's user avatar
  • 61.4k
22 votes
Accepted

How could one determine UID/GID of running process

$ stat -c "%u %g" /proc/$pid/ 1000 1000 or $ egrep "^(U|G)id" /proc/$pid/status Uid: 1000 1000 1000 1000 Gid: 1000 1000 1000 1000 or with only bash builtins: $ while read -...
Ipor Sircer's user avatar
  • 14.6k
21 votes

top / htop; group process by command

This is possible in atop. Just press p when running it. From the help: Accumulated figures: 'u' - total resource consumption per user 'p' - total resource consumption per program (i....
Nemo's user avatar
  • 584
21 votes

Why does 'top' fail to run via 'xargs'?

top is an interactive program, for instance you can type i to toggle showing idle processes. Whilst it could arrange to read from /dev/tty in practice it expects that stdin is connected to the ...
icarus's user avatar
  • 18.1k
20 votes
Accepted

How to get all processes running on each CPU core in Ubuntu?

You can do that with ps -aeF, see the C column UID PID PPID C STIME TTY TIME CMD root 1 0 0 2015 ? 00:08:07 /sbin/init Or with htop, configure it to show the ...
daisy's user avatar
  • 54.8k
20 votes

What do the "buff/cache" and "avail mem" fields in top mean?

The canonical source of this information is /usr/src/linux/Documentation/filesystems/proc.rst Buffers: Relatively temporary storage for raw disk blocks shouldn't get tremendously large (20MB or so) ...
axiqia's user avatar
  • 301
19 votes
Accepted

How does iotop calculate the relative I/O activity?

iotop shows statistics from several different origins; take care when adding up stuff. This previous discussion covers the difference between per-process read/write amounts and the system total read/...
Gilles 'SO- stop being evil''s user avatar
17 votes

upowerd consuming 100% cpu

Do you have an iphone connected to the computer? This happens to me whenever I connect my iphone to it. Linux arjun-thinkpad 4.4.7-1-lts #1 SMP Thu Apr 14 17:26:39 CEST 2016 x86_64 GNU/Linux
user128063's user avatar
17 votes
Accepted

linux command top: saving configuration

Once you have your configuration set the way you want, type W (that is a capital W) and your configuration will be saved. From the top manpage: ´W´ :Write_the_Configuration_File This will save all ...
Timothy Martin's user avatar
17 votes

Cursor disappears when running `top -n1 | head`

Best way IMHO is to make top use "batch" mode (-b flag) which is intended to be used with non-interactive use cases such as piping to another program or to a file. So, this top -n1 -b | head won't ...
Daniele Santi's user avatar
17 votes
Accepted

Does Pulseaudio leak memory?

In your example, pulseaudio is using 32MB not 3GB. The RES column is physical memory. The VIRT column shows all the virtual memory used by the process. According to man top, that includes all code, ...
Andy Dalton's user avatar
  • 14.1k
16 votes

top command on multi core processor

If you're wanting to open top immediately displaying separate CPUs without needing to press 1, you can use the -1 option. e.g.: top -1 ... %Cpu0 : 0.0 us, 0.0 sy, 0.0 ni,100.0 id, 0.0 wa, 0.0 hi,...
Leigh  McCulloch's user avatar
14 votes

How to monitor CPU/memory usage of a single process?

I'm a bit late here but I'll share my command line trick using just the default ps WATCHED_PID=$({ command_to_profile >log.stdout 2>log.stderr & } && echo $!); while ps -p $...
theist's user avatar
  • 470
14 votes

How to monitor CPU/memory usage of a single process?

Using top and awk one could easily create e.g. a comma separated log of %CPU ($9) + %MEM ($10) usage that can later be fed into any statistics and graphing tool. top -b -d $delay -p $pid | awk -v OFS=...
xebeche's user avatar
  • 911
13 votes

Is it possible to freeze task order in htop?

A similar question was asked on superuser in February https://superuser.com/questions/1036978/how-pause-list-of-process-in-htop The accepted answer is to use the -d option to change the delay of the ...
firexfly's user avatar
  • 286

Only top scored, non community-wiki answers of a minimum length are eligible