How to execute unix 'top' command with options in android How to execute unix 'top' command with options in android unix unix

How to execute unix 'top' command with options in android


After doing a lot of homework I got this working! Following way 'top' can be used with as many options:

String[] cmd = {"sh","-c",                "top -m 100 -n 1"               };Process proc = Runtime.getRuntime().exec(cmd);

I have use -m and -n options and its working great. See manual for whole list of options:'top' options


I am using

Process psProc = Runtime.getRuntime().exec("top -n 1 -d 5");

to get all the process running and then calculate CPU usage for android apps.