Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'm trying to evaluate performances of some active processes of mine on linux.

Searching the internet I found that ps and top are the only command available for that.

More precisely here, it says that top is the right command.

I need to use top -b -n 1 beacause I need to parse the output and "grep" only some information from that.

However, the top -b -n 1 output results to be very different with respect to the classic top output. This happens, I think, because the second one compute the average percentage of cpu and ram usage, whereas the first one makes a "snapshot" of the system at the time it has been launched.

Am I right? is the top -b -n 1 output a valid response or a fake one? May I use it to compute some statistics or not?

is top -b -n 1 a valuable command to get information about system and processes? are there any other commands or whatever else to evaluate performances on linux?

share|improve this question

closed as unclear what you're asking by slm, Anthon, manatwork, vonbrand, Zelda Mar 14 at 15:27

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question.If this question can be reworded to fit the rules in the help center, please edit the question.

    
Can you post some data supporting your theory about top displaying very different values depending on whether the -b option is used or not ? –  jlliagre Mar 14 at 8:50
    
it really depends on what informations you want, please when you ask a question, try to explain your goal cleary and the different things you have try so far, so we can orientate you in the right direction if you're mistaken. –  Kiwy Mar 14 at 9:19
    
thank you all for answering. Naming performances and top,ps commands I thought was enough to understand what kind of information I need. Anyway, I need cpu and ram usage of some process and total ram and total cpu usage. My question aim to undestand if those commands are enough to get these information and, most of all, if they are the right tools. I will post an example about the differences of top and top -b. –  Gappa Mar 14 at 9:27
add comment

1 Answer 1

I'm trying to evaluate performances of some active processes of mine on linux

It is rather vague what you mean when say "evaluate performances". What exactly do you want to get?

Searching the internet I found that ps and top are the only command available for that

perf is also available. https://perf.wiki.kernel.org/index.php/Tutorial.
ps can give you CPU utilization: ps --format pid,pcpu,size,vsz,cmd

top -b -n 1 output results to be very different with respect to the classic top output

Look, 1) top is an open source and you can take a look at the source code. http://procps.sourceforge.net/ 2) If you analyze how top works with strace in the batch mode and in the screen mode then you will see that they open the same files in /proc (you can read man proc):

open("/sys/devices/system/cpu/online", O_RDONLY|O_CLOEXEC) = 3
open("/proc/sys/kernel/pid_max", O_RDONLY) = 3
open("/etc/toprc", O_RDONLY)            = -1 ENOENT (No such file or directory)
open("/home/.toprc", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/terminfo/x/xterm-256color", O_RDONLY) = 3
open("/proc", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = 3
open("/proc/1/stat", O_RDONLY)          = 4
open("/proc/1/statm", O_RDONLY)         = 4
open("/proc/2/stat", O_RDONLY)          = 4
... some lines skipped by me ...
open("/proc/27004/stat", O_RDONLY)      = 4
open("/proc/27004/statm", O_RDONLY)     = 4
open("/proc/27006/stat", O_RDONLY)      = 4
open("/proc/27006/statm", O_RDONLY)     = 4
open("/etc/localtime", O_RDONLY)        = 3
open("/proc/uptime", O_RDONLY)          = 3
open("/var/run/utmp", O_RDONLY|O_CLOEXEC) = 4
open("/proc/loadavg", O_RDONLY)         = 4
open("/proc/stat", O_RDONLY)            = 5
open("/proc/meminfo", O_RDONLY)         = 6

is the top -b -n 1 output a valid response or a fake one

I took a look at the source code and see that the "-b" option only set Batch flag which affects how it display info, not how it calculate the numbers. So, please, check again your test

Batch = 0,          /* batch mode, collect no input, dumb output */
share|improve this answer
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.