Reputation: 3059
I'm trying to use the "top" command from a standalone java app. I basically want to run this:
top -p myProcessId -n 1 -b
my java psuedocode:
Process process = Runtime.getRuntime().exec("top -p myProcessId -n 1 -b");
// read both:
process.getInputStream();
process.getErrorStream()
and the output I get is:
top: failed tty get
I'm not sure what that output means - any ideas how to use "top" correctly here? I'm on ubuntu fwiw.
Thanks
----- Update -------------
OK I was able to do this instead with:
ps -Ao pid,rsz,cmd
and then I read through each output line for the process I'm interested in, I can read the res mem value from there.
Upvotes: 0
Views: 1349
Reputation: 77226
top
doesn't use the ordinary standard output stream; it manipulates the terminal device directly. This means that you can't just read in its output like you can from most command-line programs. There are a few other programs that might do what you need (ps
is a likely candidate), or you might be able to read the relevant information from /proc
.
Upvotes: 1