二、对于第三种,我们都知道在linux shell中输入ps命令,可以查看所有运行的进程,
root@android:/ #
root@android:/ # ps
USER PID PPID VSIZE RSS WCHAN PC NAME
root 1 0 412 244 c00cf1c0 0000ffe4 S /init
root 2 0 0 0 c0044560 00000000 S kthreadd
root 3 2 0 0 c002eae4 00000000 S ksoftirqd/0
root 6 2 0 0 c007aaa4 00000000 S migration/0
root 7 2 0 0 c007dfb0 00000000 S watchdog/0
root 12 2 0 0 c003fd14 00000000 S khelper
root 13 2 0 0 c003fd14 00000000 S netns
.......
root 17 2 0 0 c003fd14 00000000 S suspend_sys_syn
u0_a55 16896 1413 545192 52208 ffffffff 4010eea4 S com.tencent.mm
u0_a55 16934 1413 526176 34352 ffffffff 4010eea4 S com.tencent.mm:push
u0_a37 17719 1413 512816 30040 ffffffff 4010eea4 S com.nufront.NufrontTestDemo
u0_a25 17835 1413 487536 22400 ffffffff 4010eea4 S com.android.smspush
root 18674 1432 928 544 c0011ad4 40160934 S /system/bin/sh
root 18688 18674 1236 460 00000000 400bfd38 R ps
再执行kill命令,就可以杀死对应的进程
root@android:/ # kill 16896
再有,如果执行ps | grep试试看:
root@android:/ #
root@android:/ #ps | grep tencent
u0_a55 16896 1413 545192 52208 ffffffff 4010eea4 S com.tencent.mm
u0_a55 16934 1413 526176 34352 ffffffff 4010eea4 S com.tencent.mm:push
root@android:/ #
在android中有一个函数是有kill命令功能的: Process.killProcess(int pid);
所以,我们只需要根据package name,找到没有被杀死的进程的进程号,再调用killprocess()函数,就可以杀死一直杀不死的进程了。可参考下面的代码:
java.lang.Process process=null;
Runtime rt=Runtime.getRuntime();
System.out.println("start");
try {
process=rt.exec("busybox pgrep nuomi");
InputStream is=null;
InputStreamReader isr=null;
BufferedReader buffer=null;
String line=null;
String xxx = null;
is=process.getInputStream();
isr=new InputStreamReader(is);
buffer=new BufferedReader(isr);
while((line=buffer.readLine())!=null){
System.out.println(line+"----------");
Process.killProcess(Integer.valueOf(line));
xxx = line;
}
System.out.println(xxx+"***********");
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("end");
三、另外一些关于应用程序的函数可参考下面
参考:androidbin.iteye.com/blog/1594908,blog.sina.com.cn/s/blog_3e333c4a01015v3e.html等,谢谢!!!
联系客服