static boolean is_proccess_alive(String test_suite) { int count = 0; // String search_proccess_cmd = String.format(cmd_format, test_suite); // RunnerCmnDef.DumpDebugMsg("Search for the process by command: %s", search_proccess_cmd);\ String cmdArr[] = {"ps", "aux"}; try { Process p = Runtime.getRuntime().exec(cmdArr); BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream())); String res = stdInput.readLine(); while ((res = stdInput.readLine()) != null) { if (res.indexOf(rat22_process_keyword) >= 0) { if (res.indexOf(test_suite) >= 0) { RunnerCmnDef.DumpDebugMsg("The %s process found: %s", test_suite, res); count++; } } } } catch (Exception ex) { RunnerCmnDef.DumpErrorMsg( "Error occur while searching for rat22 process[%s], dut to: %s", rat22_process_keyword, ex.toString()); } if (count > 1) RunnerCmnDef.DumpWarningMsg( "More than 1 related process[%s] are found", Integer.toString(count)); return (count > 0 ? true : false); }
public static void main(String args[]) { int count = 0; String cmd = "ps aux | grep tcpdump"; String cmdArr[] = {"ps", "aux"}; // RunnerCmnDef.DumpDebugMsg("Search for the process by command: %s", cmd); // RunnerCmnDef.DumpDebugMsg("Check1"); // RunnerCmnDef.DumpDebugMsg("Check2"); // RunnerCmnDef.DumpDebugMsg("Check3"); // RunnerCmnDef.DumpDebugMsg("Check4"); // RunnerCmnDef.DumpDebugMsg("Check5"); // RunnerCmnDef.DumpDebugMsg("Check6"); // RunnerCmnDef.DumpDebugMsg("Check7"); // RunnerCmnDef.DumpDebugMsg("Check8"); // RunnerCmnDef.DumpDebugMsg("Check9"); // RunnerCmnDef.DumpDebugMsg("Check0"); String test_suite = "multi_cluster"; boolean found = is_proccess_alive(test_suite); if (found) System.out.println("Found !!!"); else System.out.println("Not Found !!!"); // try // { // Process p = Runtime.getRuntime().exec(cmdArr); // BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream())); // BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream())); // // while (true) // { // String res = stdInput.readLine(); // if (res == null) // break; // // if (res.indexOf("tcpdump") >= 0) // { // String strMsg = String.format("Found: %s\n", res); // System.out.printf(strMsg); // RunnerCmnDef.DumpInfoMsg(strMsg); // count++; // } //// else //// { //// System.out.printf("res: %s\n", res); //// } //// RunnerCmnDef.DumpDebugMsg("Process: %s found !!!", res); // } //// while ((res = stdError.readLine()) != null) //// { //// RunnerCmnDef.DumpDebugMsg("Process: %s found !!!", res); //// count++; //// } // // } // catch (Exception ex) // { // RunnerCmnDef.DumpErrorMsg("Error occur while executing command[%s], dut to: %s", cmd, // ex.toString()); // } // System.out.printf("Count: %d\n", count); // // if (count > 1) // { // String strMsg = String.format("More than 1 related process[%d] are found", count); // RunnerCmnDef.DumpWarningMsg(strMsg); // } RunnerCmnDef.DumpDebugMsg("Done..."); // try // { // Thread.sleep(5000); // } // catch(Exception ex) // { // // } RunnerCmnDef.Wait2WriteLog(); System.out.println("The proccess is dead"); }