You need to run "top" command with the -b option to execute the top
command in batch mode (instead of interactive mode) to avoid top failing
with error "top: failed tty get". And specify the "-n 1" option to
indicate to run only one iteration before ending.
About options -b and -n from the top command man page:
-b : Batch mode operation
Starts top in "Batch mode", which could be useful for sending
out-
put 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â command-line option or until killed.
-n : Number of iterations limit as: -n number
Specifies the maximum number of iterations, or frames, top
should
produce before ending.
For more information on how to capture the output from the "top" command
to a file, see
http://www.thegeekstuff.com/2009/10/how-to-capture-unix-top-command-output-to-a-file-in-readable-format/
.
So, run a STAF PROCESS START command like the following to return the top
command's output in the result. In addition to working fine using the
STAF command line executable, it will also work fine when submitting this
PROCESS START request via a Java program using the STAF APIs for Java.
# STAF machine PROCESS START SHELL COMMAND "top -n 1 -b" RETURNSTDOUT
STDERRTOSTDOUT WAIT
Response
--------
{
Return Code: 0
Key : <None>
Files : [
{
Return Code: 0
Data : top - 10:09:25 up 139 days, 17:13, 1 user, load
average: 0.
00, 0.00, 0.00
Tasks: 150 total, 1 running, 149 sleeping, 0 stopped, 0 zombie
Cpu(s): 0.4%us, 0.1%sy, 0.0%ni, 99.5%id, 0.1%wa, 0.0%hi, 0.0%si,
0.0%st
Mem: 8177356k total, 6889868k used, 1287488k free, 384012k buffers
Swap: 10223608k total, 124k used, 10223484k free, 6045376k cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
1151 root 15 0 12756 1032 736 R 2.0 0.0 0:00.01 top
1 root 15 0 10368 640 544 S 0.0 0.0 0:03.96 init
2 root RT -5 0 0 0 S 0.0 0.0 0:16.52 migration/0
3 root 34 19 0 0 0 S 0.0 0.0 0:01.82 ksoftirqd/0
4 root RT -5 0 0 0 S 0.0 0.0 0:00.00 watchdog/0
5 root RT -5 0 0 0 S 0.0 0.0 0:01.74 migration/1
... <Deleted additional output here>
4833 gdm 15 0 218m 19m 8096 S 0.0 0.2 0:00.50 gdmgreeter
5134 root 18 0 263m 11m 8632 S 0.0 0.1 0:09.75 kcawd
17226 root 15 0 0 0 0 S 0.0 0.0 2:56.00 pdflush
31685 root 15 0 0 0 0 S 0.0 0.0 0:29.52 pdflush
}
]
}
--------------------------------------------------------------
Sharon Lucas
IBM Austin, luc...@us.ibm.com
(512) 286-7313 or Tieline 363-7313
From: Tun Wei <wei...@gmail.com>
To: "staf-users@lists.sourceforge.net"
<staf-users@lists.sourceforge.net>,
Date: 10/16/2013 09:25 AM
Subject: [staf-users] STAF woks with TOP on unix
Hi, everybody, probably this is an old question. I am wondering if there
is a simple way to get TOP result on unix. Right now, I tried this
command: STAF <my_unix> PROCESS START SHELL COMMAND "top" RETURNSTDOUT
STDERRTOSTDOUT WAIT . But, obviously it is not right because it returns me
"Data :top: failed tty get". So, is there any good way to get the
result?
By the way, I eventually need to call this STAF command in Java. So, I am
looking for a good way to do this STAF-unix-top in Java too
Thank you very much for your time and suggestions
Tun
------------------------------------------------------------------------------
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most
from
the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60135031&iu=/4140/ostg.clktrk
_______________________________________________
staf-users mailing list
staf-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/staf-users
------------------------------------------------------------------------------
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from
the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60135031&iu=/4140/ostg.clktrk
_______________________________________________
staf-users mailing list
staf-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/staf-users