<tfoot id='YofPJ'></tfoot>

    <small id='YofPJ'></small><noframes id='YofPJ'>

      <bdo id='YofPJ'></bdo><ul id='YofPJ'></ul>
    1. <legend id='YofPJ'><style id='YofPJ'><dir id='YofPJ'><q id='YofPJ'></q></dir></style></legend>
    2. <i id='YofPJ'><tr id='YofPJ'><dt id='YofPJ'><q id='YofPJ'><span id='YofPJ'><b id='YofPJ'><form id='YofPJ'><ins id='YofPJ'></ins><ul id='YofPJ'></ul><sub id='YofPJ'></sub></form><legend id='YofPJ'></legend><bdo id='YofPJ'><pre id='YofPJ'><center id='YofPJ'></center></pre></bdo></b><th id='YofPJ'></th></span></q></dt></tr></i><div id='YofPJ'><tfoot id='YofPJ'></tfoot><dl id='YofPJ'><fieldset id='YofPJ'></fieldset></dl></div>

      如何使用 Java 获取 chromedriver 进程 PID?

      时间:2023-09-28
      • <i id='IJ8P2'><tr id='IJ8P2'><dt id='IJ8P2'><q id='IJ8P2'><span id='IJ8P2'><b id='IJ8P2'><form id='IJ8P2'><ins id='IJ8P2'></ins><ul id='IJ8P2'></ul><sub id='IJ8P2'></sub></form><legend id='IJ8P2'></legend><bdo id='IJ8P2'><pre id='IJ8P2'><center id='IJ8P2'></center></pre></bdo></b><th id='IJ8P2'></th></span></q></dt></tr></i><div id='IJ8P2'><tfoot id='IJ8P2'></tfoot><dl id='IJ8P2'><fieldset id='IJ8P2'></fieldset></dl></div>
        <legend id='IJ8P2'><style id='IJ8P2'><dir id='IJ8P2'><q id='IJ8P2'></q></dir></style></legend>
            <tbody id='IJ8P2'></tbody>

            <small id='IJ8P2'></small><noframes id='IJ8P2'>

            • <bdo id='IJ8P2'></bdo><ul id='IJ8P2'></ul>

            • <tfoot id='IJ8P2'></tfoot>

                本文介绍了如何使用 Java 获取 chromedriver 进程 PID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                我遇到了一个问题.有时,当我的 JUnit 测试运行时,命令 webDriver.quit();没有杀死 chromedriver 进程,因此下一个测试无法开始.在这种情况下,我想添加一些可能会在 Linux 上手动终止进程的方法,但我不知道如何获取 chromedriver 的 PID,因此我可以执行以下操作:Runtime.getRuntime().exec(KILL + PID);

                I've faced a problem. Sometimes, while my JUnit tests are running, command webDriver.quit(); isn't killing chromedriver process so the next test can't start. In that case I want to add some method which may kill process manually on Linux, but I can't figure out how to get PID of chromedriver so I can do something like: Runtime.getRuntime().exec(KILL + PID);

                推荐答案

                你可以使用 pgrep 找到 PID,然后杀死它:

                You can find PIDs using pgrep and then kill it:

                    private void killChromedriver() throws IOException, InterruptedException {
                        String command = "pgrep chromedriver";
                        Process process = Runtime.getRuntime().exec(command);
                        BufferedReader br = new BufferedReader(new InputStreamReader(process.getInputStream()));
                        List<String> processIds = getProcessedIds (process, br);
                        for (String pid: processIds) {
                                Process p = Runtime.getRuntime().exec("kill -9 " + pid);
                                p.waitFor();
                                p.destroy();
                        }
                    }
                    private List<String> getProcessedIds(Process process, BufferedReader br) throws IOException, InterruptedException {
                        process.waitFor();
                
                        List<String> result = new ArrayList<>();
                        String processId ;
                
                        while (null != (processId = br.readLine())) {
                            result.add(processId);
                        }
                
                        process.destroy();
                        return result;
                    }
                

                <小时>

                更新

                另一个更简单的解决方案似乎是

                Another and more simple solution seems to be

                    Runtime.getRuntime().exec("pkill chromedriver");
                

                这篇关于如何使用 Java 获取 chromedriver 进程 PID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:java.lang.IllegalStateException:驱动程序可执行文件不存 下一篇:如何隐藏警告“此类文件可能会损害您的计算机

                相关文章

                最新文章

              1. <legend id='0Ay0r'><style id='0Ay0r'><dir id='0Ay0r'><q id='0Ay0r'></q></dir></style></legend>

                  • <bdo id='0Ay0r'></bdo><ul id='0Ay0r'></ul>

                  <tfoot id='0Ay0r'></tfoot>

                  <small id='0Ay0r'></small><noframes id='0Ay0r'>

                    <i id='0Ay0r'><tr id='0Ay0r'><dt id='0Ay0r'><q id='0Ay0r'><span id='0Ay0r'><b id='0Ay0r'><form id='0Ay0r'><ins id='0Ay0r'></ins><ul id='0Ay0r'></ul><sub id='0Ay0r'></sub></form><legend id='0Ay0r'></legend><bdo id='0Ay0r'><pre id='0Ay0r'><center id='0Ay0r'></center></pre></bdo></b><th id='0Ay0r'></th></span></q></dt></tr></i><div id='0Ay0r'><tfoot id='0Ay0r'></tfoot><dl id='0Ay0r'><fieldset id='0Ay0r'></fieldset></dl></div>