View Single Post
Old 08-27-2011, 02:01 PM   #13
fbdev
fbdev
fbdev really knows where his or her towel isfbdev really knows where his or her towel isfbdev really knows where his or her towel isfbdev really knows where his or her towel isfbdev really knows where his or her towel isfbdev really knows where his or her towel isfbdev really knows where his or her towel isfbdev really knows where his or her towel isfbdev really knows where his or her towel isfbdev really knows where his or her towel isfbdev really knows where his or her towel is
 
Posts: 107
Karma: 70177
Join Date: Jul 2011
Device: kindle
one thing i REALLY hate about shell scripting is that it's so cryptic.
if C is beautiful, and it is, bash and perl are on the wrong end of the ugly stick in a hurricane.

let me explicate this bit of code.

while sleep 1:
loop until interrupt at one second intervals

; do
now the body of the loop

awk '{ print $15 }'
print the fifteenth column of a file

`pgrep cvm`
the pid of cvm (the java framework)

/proc/`pgrep cvm`/stat
the name of the file is:
/proc/4455/stat
if the pid of the cvm process is 4455

the stat file holds process statistics for a process.
column 15 of this file is the user mode jiffies (think cpu cycles used) for the process.
more info on the stat file.

; done
end of the loop body

|/tmp/fbout
send the output of this loop to the framebuffer.

putting the pipe at the end of the loop instead of here:
# while sleep 1; do awk '{ print $15 }' /proc/`pgrep cvm`/stat|/tmp/fbout; done

causes executions of the command to reuse the pipe instead of reopening it every time.

Quote:
Originally Posted by fbdev View Post
the complete answer to this question is complicated.

i usually use it like this:
# while sleep 1; do awk '{ print $15 }' /proc/`pgrep cvm`/stat; done|/tmp/fbout
fbdev is offline   Reply With Quote