you can get a reference to the process like this
Process p = Runtime.getRuntime().exec("/usr/bin/top");
then read its output something like this
BufferedReader reader;
reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
you could try using the getOutputStream() method to get an OutputStream you
could write your 'q' or control-c command to the 'top' process.