Hot answers tagged

416

Use the top command in Linux/Unix: top press shift+m after running the top command or you can interactively choose which column to sort on press Shift+f to enter the interactive menu press the up or down arrow until the %MEM choice is highlighted press s to select %MEM choice press enter to save your selection and exit the interactive menu Or specify the ...


202

When in top, typing capital "E" cycles through different memory units (kb, mb, gb etc) in the total memory info: While lower-case "e" does the same individual process lines: From the manpage: 2c. MEMORY Usage This portion consists of two lines which may express values in kibibytes (KiB) through exbibytes (EiB) depending on the scaling factor ...


182

You can switch the memory unit by pressing e. E will select the memory unit in the top summary bar. Use W to permanently write your configuration to /home/user/.toprc and see also ? for more configuration options.


99

The command line option -o (o standing for "Override-sort-field") also works on my Xubuntu machine and according to the Mac man page of top it should work on a Macintosh too. If I want to short by memory usage I usually use top -o %MEM which sorts by the column %MEM. But I can use VIRT, RES or SHR too. On a Macintosh I would probably use mem or vsize. I ...


99

%CPU -- CPU Usage : The percentage of your CPU that is being used by the process. By default, top displays this as a percentage of a single CPU. On multi-core systems, you can have percentages that are greater than 100%. For example, if 3 cores are at 60% use, top will show a CPU use of 180%. See here for more information. You can toggle this ...


93

hi is the time spent processing hardware interrupts. Hardware interrupts are generated by hardware devices (network cards, keyboard controller, external timer, hardware sensors, ...) when they need to signal something to the CPU (data has arrived, for example). Since these can happen very frequently, and since they essentially block the current CPU while ...


86

man ps in NOTES section. CPU usage is currently expressed as the percentage of time spent running during the entire lifetime of a process. This is not ideal, and it does not conform to the standards that ps otherwise conforms to. CPU usage is unlikely to add up to exactly 100%. And, guess you know, but you can also do: top -p <PID> ...


68

There is a command-line option which does that: -M : Detect memory units Show memory units (k/M/G) and display floating point values in the memory summary. So it is sufficient to run top like that: top -M If -M does not work you can press E while already in top. From man top (procps-ng version 3.3.9): E :Extend-Memory-Scale ...


64

I'm not entirely sure what you're asking here. Yes, top shows CPU usage as a percentage of a single CPU by default. That's why you can have percentages that are >100. On a system with 4 cores, you can see up to 400% CPU usage. You can change this behavior by pressing I (that's Shift + i and toggles "Irix mode") while top is running. That will cause it to ...


63

To add to the answers already P (upper case P) makes top order by CPU, Then hit W (again upper case W) to save. M goes back to memory


59

psrecord The following addresses history graph of some sort. Python psrecord package does exactly this. pip install psrecord # local user install sudo apt-get install python-matplotlib python-tk # for plotting; or via pip For single process it's the following (stopped by Ctrl+C): psrecord $(pgrep proc-name1) --interval 1 --...


57

ps and top display CPU time used, not clock time since the process started. One way to check when the process started is use the following command. The PID file creation date is when the process started: ls -ld /proc/pid So for process 2303 it would be: ls -ld /proc/2303


47

minutes:seconds.hundredths Searching for “TIME+” or for “seconds” gives the answer, kind of (I wouldn't call the man page clear). This format is inherited from BSD, you also get it with ps u or ps l under Linux.


47

You can also use htop. It's much cooler than top. If you are using Debian or one of its derivatives, then you can install it using sudo apt-get install htop. Edit: Here is a screenshot with a better color scheme:


43

This will show you top 10 process that using the most memory: ps aux --sort=-%mem | awk 'NR<=10{print $0}' using top: when you opened top press m will short process based on memory usage. But this will not solve your problem, in Linux everything is either file or process. so the files you opened will eating the memory too. so this will not help. lsof ...


40

You can change the sort field in the interactive top window with the < and > keys. I'm not sure what operating system you're running but at least on my GNU top, k is supposed to kill, not reset. Presumably, your friend changed the sort field and hit Shift+W to save to ~/.toprc. Just use the keys I mentioned to choose the sort field you want and then, ...


39

From my other answer here, you could do something like, top -p `pgrep "java"`


35

top -M doesn't work on any of the Fedora, Debian or Ubuntu distros to my knowledge. I just tried it and it's not in the procps-ng package that provides top. There are many implementations of top so one needs to pay special attention to which they use. In general it's best to use free with switching to get the amount of memory free on Linux. procps vs. ...


33

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 Linux 2.5.41) (5) Time waiting for I/O to complete. This value is not reliable, for the following reasons: The CPU will not wait for I/O to ...


29

You are in a multi-core/multi-CPU environment and "top" is working in Irix mode. That means that your process (vlc) is performing a computation that keeps 1.2 CPUs/cores busy. That could mean 100%+20%, 60%+60%, etc. Press 'I' to switch to Solaris mode. You get the same value divided by the number of cores/CPUs.


29

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 /proc/meminfo) buff/cache Sum of buffers and cache available Estimation of how much memory is available for ...


26

F1 or h will show you the legend. It looks like in this color scheme: CPU: blue is for low priority threads green is normal priority threads black is for io-wait see below for more. Memory: green is memory in use blue is buffer orange is cache


23

You can press the following keys: e -- Change the scaling factor on the summary display Shift+e -- Change the scaling factor on the task Shift+w -- Save current settings


23

You can simply use grep: NAME grep, egrep, fgrep, rgrep - print lines matching a pattern SYNOPSIS grep [OPTIONS] PATTERN [FILE...] grep [OPTIONS] [-e PATTERN | -f FILE] [FILE...] DESCRIPTION grep searches the named input FILEs (or standard input if no files are named, or if a single hyphen-minus (-) is given as file ...


22

Something like this? (while kill -0 $pid; do sleep 1; done) && echo "finished" Replace $pid with the process id and echo "finished" with whatever you want to do when the process exited. For example: (while kill -0 $pid; do sleep 1; done) && mail ...


21

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 separated by a newline by default. use the -d "," to separate it by , as required by the top. If you see error like top: -p argument missing, it means no java ...


20

A process in S state is usually in a blocking system call, such as reading or writing to a file or the network, or waiting for another called program to finish. You can use strace -p <pid> to find out which system call is currently happening. It will produce output like write(1, "foobar"..., 4096 which means that the process is trying to write ...


20

In Linux, you can try this: top -bn1 > output.txt From man top: -b : Batch-mode operation Starts top in 'Batch' mode, which could be useful for sending output from top to other programs or to a file. In this mode, top will not accept input and runs until the iterations limit you've set with the '-n' ...


19

The command field is by default truncated automatically for better reading. You need to run top -c to show full command then depending on your console window's capabilities you would be able to scroll to right and see full command.


19

top is a full screen interactive console application. It requires a tty to run. Try ssh -t or ssh -tt to force pseudo-tty allocation.


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