In Linux, What Do All the Values in the "Top" Command Mean

In Linux, what do all the values in the top command mean?

The man page says what the state codes are mapped to, but not what they actually mean. From the top man page:

'D' = uninterruptible sleep
'R' = running
'S' = sleeping
'T' = traced or stopped
'Z' = zombie

'R' is the easiest; the process is ready to run, and will run whenever its turn to use the CPU comes.

'S' and 'D' are two sleep states, where the process is waiting for something to happen. The difference is that 'S' can be interrupted by a signal, while 'D' cannot (it is usually seen when the process is waiting for the disk).

'T' is a state where the process is stopped, usually via SIGSTOP or SIGTSTP. It can also be stopped by a debugger (ptrace). When you see that state, it usually is because you used Ctrl+ Z to put a command on the background.

'Z' is a state where the process is dead (it has finished its execution), and the only thing left is the structure describing it on the kernel. It is waiting for its parent process to retrieve its exit code, and not much more. After its parent process is finished with it, it will disappear.

Linux system,use top command, what is the meaning of 'I' in top command S column,S --status

top version:
procps-ng 3.3.15

man top:

29. S  --  Process Status
The status of the task which can be one of:
D = uninterruptible sleep
I = idle
R = running
S = sleeping
T = stopped by job control signal
t = stopped by debugger during trace
Z = zombie

What do top %cpu abbreviations mean?

In "top" what are us, sy, ni, id, wa, hi, si and st (for CPU usage)?

  • us - user cpu time (or) % CPU time spent in user space
  • sy - system cpu time (or) % CPU time spent in kernel space
  • ni - user nice cpu time (or) % CPU time spent on low priority processes
  • id - idle cpu time (or) % CPU time spent idle
  • wa - io wait cpu time (or) % CPU time spent in wait (on disk)
  • hi - hardware irq (or) % CPU time spent servicing/handling hardware interrupts
  • si - software irq (or) % CPU time spent servicing/handling software interrupts
  • st - steal time % CPU time in involuntary wait by virtual cpu while hypervisor is servicing another processor (or) % CPU time stolen from a virtual machine

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

What is a brief explanation of the syntax of the following top command: top -p `pgrep process-name | tr \\n , | sed 's/,$//'`

I'll try to break it down by answering your question in pieces.

The first piece we'll look at is sed 's/,$//'. I'm not going to be able to briefly explain the sed command but please look at the GNU sed manual for more information. The 's/,$//' is telling sed to look for any commas at the end of a line and substitute them with nothing. This is removing all the commas from the end of each line on sed's standard input.

The next piece we'll look at at is tr "\\n" ",". Again, tr can do many things but its purpose is to transform characters. See tr man page for a more detailed explanation. This usage is to turn all UNIX newline characters (\n) into commas. The \ has to be escaped with an additional \ because the command line would treat the \n as a new line and break the command.

Next is pgrep process-name. For completeness here is the pgrep man page. pgrep simply prints the process id (pid) of any running process that matches the selection criteria to standard out. Each pid will be printed on a line by itself. Here we are looking for the pid of the command process-name.

Now for pipe (|). This creates a new process and sends anything printed on standard out to the standard in of the new process.

Lets look at the commands to understand how pipe works better. pgrep process-name | tr "\\n" "," will print all pid's matching process-name to standard out which is passed to the standard input of the process running tr. tr "\\n" "," | sed 's/,$//' will transform all newlines from its standard in to commas and print the result to its standard out which is passed to the new process running sed 's/,$//'.

So the entire command pgrep process-name | tr "\\n" "," | sed 's/,$//' will print a space separated line of pid's for any running process that has the name process-name.

Two more pieces to look at: top -p and the backticks (``). Backticks creates a new process that runs the commands inside and substitutes its standard out before the entire command is evaluated. For example:

echo `echo "Hello, World!"`

prints Hello, World! to the screen.

Lastly, top -p takes a list of pids and reports various information such as run time, memory usage and nice value. For a more detailed explanation see the top man page.

Does any one know the 'top' command 's result's meaning in android?

Here's my (un)educated guesses:

PID - Process ID

CPU% - CPU Usage

S - State (or possibly status) R=Running, S=Sleeping

#THR - Number of threads

PCY - I'm kinda stumped here. You seem to have a pretty good grasp of what it does, so that's good enough (assuming that fg and bg are the only possible values)

UID - Name of the user that started the task

Name - This one is self-explanatory...

VSS and RSS: From http://groups.google.com/group/android-beginners/browse_thread/thread/e6f2d396a68238ad?pli=1

Virtual Set Size (sometimes abbreviated VSZ) and Resident Set Size.
Googling will turn up some detailed info for Linux. Here's the high
speed version:

VSS indicates how much virtual memory is associated with the process,
Resident Set Size indicates how many physical pages are associated
with the process.

VSS is generally meaningless on Android. If I memory-map a 1MB file,
VSS grows by 1MB, but I haven't used any resources (other than entries
in a virtual mapping table).

RSS is partially meaningless on Android, because it doesn't identify
pages shared between multiple processes. If process A has an RSS of
2MB, and process B has an RSS of 2MB, it's possible that there are 4MB
of physical pages occupied. It's also possible that there are only
2MB of physical pages occupied.

EDIT:
As far as your Youtube is sleeping deal, if it isn't actively doing anything, it will be sleeping, even if it is in the foreground. Try creating a simple app that is basically while(1){Do something meaningless} and see if it is sleeping or running. Granted it also might be a quirk with the way that Android handles multitasking.

EDIT2:

Mostly-uneducated-somewhat-random-stab-in-the-dark for PCY --

PCY -- Policy -- Determines how an app should be treated by Android's memory manager

FG -- Foreground -- Process is considered a foreground process and should not be killed to free mmemory

BG -- Background -- Process is considered a background process (not actively running in foreground and may be killed to free memory)

Is there an argument for the top command to get a permanent result?

top -n1

should do the job. If you want to store the output in a file, you should add the -b option for batch mode.

Note that this is just a sample of usage at one time, not anything like a final answers as all the numbers in top vary over time even on the stablest of systems.

top command first iteration always returns the same result

CPU utilisation figures are calculated as an average over a time interval. For the first iteration, that time interval is "from system boot until now"; for subsequent iterations, the time interval is "from the last iteration until now".

Parsing values from TOP command and then add them up

if your 9th column in /home/user/top_VM.txt containts number like this :

10

12.5

0

0.5

...

you can do :

awk '{ sum+=$9} END {print sum}' /home/user/top_VM.txt

if your 9th column dont contains only number you can do :

#The first awk is to get only number part (12.3 from 12.3%cpu)
awk '{printf ("%f\n",$9)} ' /home/user/top_VM.txt | awk '{ sum+=$1} END {print sum} '

in order to calculate cpu % for each one of your snapshots you can use the following script :

#!/bin/bash
count="0"
VM="VM cpu usage : "
SUM="ONSTART"

while read line ;
do
#extract the first word in each line
TMP=$(echo $line | awk '{printf $1}')

#if its equal to PID then we have a new snapshot
#SUM variable is to prevent writing to result file before calculating cpu% the first time we have a snapshot
if [[ "$TMP" == "PID" && "$SUM" == "NEWVM" ]] ; then
#increment snapshot number
let count++
echo "$count $VM $NUM" >> result
NUM="0"
fi

#if we have a number so its the pid of a process
if [[ $TMP =~ ^[0-9]+$ ]] ; then
#get cpu value
NEWNUM=$(echo $line | awk '{printf ("%f\n",$9)}')
#add new value to previous ones
NUM=$( echo "$NUM $NEWNUM" | awk '{print $1 + $2}')
SUM="NEWVM"
fi

done < /home/user/top_VM.txt
#Save cpu usage for the last snapshot
let count++
echo "$count $VM $NUM" >> result

top -c command in linux to filter processes listed based on processname

Using pgrep to get pid's of matching command lines:

top -c -p $(pgrep -d',' -f string_to_match_in_cmd_line)

top -p expects a comma separated list of pids so we use -d',' in pgrep. The -f flag in pgrep makes it match the command line instead of program name.



Related Topics



Leave a reply



Submit