如何杀死firefox子进程/ tab从Java / C ++ [英] How to kill firefox child process/tab from Java/C++
问题描述
我有我的应用程序在Java中调用浏览器[IE或Firefox等]。
I have my application in Java which invokes a browser [IE or Firefox etc ] ..
要求是当我的Java应用程序退出我必须杀死所有的网络
Requirement is when my Java Application exits i have to kill all the web pages [Child processes ] i have opened from my Application in IE/Firefox etc..
我使用下面的代码。
注意: cmd 包含系统浏览器exe路径和网址
Note : cmd contains "System Browser exe path and URL"
static ArrayList<Process> pro = new ArrayList<Process>();
String cmd=" ";
Process p = Runtime.getRuntime().exec(cmd);
pro.add(p);
我维护一个静态数组列表来添加所有的进程对象。
I maintain a static arraylist to add all the process objects .
为了杀死我调用的进程,我使用下面的代码
To kill the process i invoked i use the below code
Iterator<Process> iter = pro.iterator();
while(iter.hasNext()){
Process p = iter.next();
System.out.println("Now Killing "+p.toString());
p.destroy();
}
此代码[ p.destroy(); ]正在为Internet Explorer正常工作,但它不适用于Firefox / Chrome ...
This code[p.destroy();] is working fine for Internet Explorer , But its not working for Firefox/Chrome...
由于Firefox作为Main进程运行,我调用的进程为child:(...
Since Firefox runs as a Main process and the process what i invoke goes as its child :(...
我必须对Windows和Linux使用通用修正。
I have to use generic fix for Windows and Linux..
甚至去C ++文件修复这做了一些搜索条件..so,我可以从我的代码使用
I can even go for C++ file fix which does this with some search criteria ..so that i can execute that executable from my code using
Runtime.getRuntime()。exec(可执行cmd);
Runtime.getRuntime().exec("executable cmd");
推荐答案
在Windows中,您可以执行:
In windows, you can run :
wmic process get description,executablepath,processid | findstr firefox
然后你可以使用 tskill PID
来终止进程
。
which will give you the PID of the firefox process. Then you can use tskill PID
to kill
the process.
这篇关于如何杀死firefox子进程/ tab从Java / C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!