95 lines
3.2 KiB
Java
95 lines
3.2 KiB
Java
package itn.com.cmm.util;
|
|
|
|
import java.io.BufferedReader;
|
|
import java.io.InputStreamReader;
|
|
|
|
public class OsProcessCheckUtil {
|
|
|
|
/**
|
|
* 운영체제의 특정 프로세스 실행여부 확인하는 유틸
|
|
*
|
|
* */
|
|
|
|
public static String WindowProcessCheck(String processNm) throws Exception{
|
|
|
|
String line ="";
|
|
String pId="";
|
|
|
|
try {
|
|
|
|
Process p = Runtime.getRuntime().exec(System.getenv("windir") +"\\system32\\"+"tasklist.exe");
|
|
BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
|
|
while ((line = input.readLine()) != null) {
|
|
System.out.println(line); //<-- Parse data here.
|
|
String [] words = line.split(" ");
|
|
String [] procInfo = new String[10];
|
|
if (words[0].contains(processNm)){
|
|
//System.out.println(line);
|
|
int nCnt = 0;
|
|
for(String item : words){
|
|
if (item.equals(""))
|
|
continue;
|
|
System.out.print(item + " ");
|
|
procInfo[nCnt] = item;
|
|
nCnt++;
|
|
}
|
|
|
|
System.out.println("Process Name : "+ procInfo[0]);
|
|
System.out.println("Process ID : "+ procInfo[1]);
|
|
System.out.println("Memory Usage : "+ procInfo[4]);
|
|
pId = procInfo[1];
|
|
}
|
|
}
|
|
input.close();
|
|
} catch (Exception err) {
|
|
err.printStackTrace();
|
|
}
|
|
|
|
return pId;
|
|
}
|
|
|
|
public static String LinuxProcessCheck(String processNm) throws Exception{
|
|
|
|
String line ="";
|
|
String pId="";
|
|
|
|
try {
|
|
|
|
System.out.println("++++++++++++++++processNm++++++++++++++++++++++++"+processNm);
|
|
String[] cmd = {"ps -ef | grep EnDeServer"};
|
|
Process p = Runtime.getRuntime().exec(cmd);
|
|
System.out.println("+++++++++++++++++++++++ppppppppppppppppppp++++++++++++++++++++++++++++++"+p);
|
|
|
|
BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
|
|
System.out.println("++++++++++++++++++++++++while Start++++++++++++++++++++++++++++++++++");
|
|
System.out.println("+++++++++++++++input.readLine()+++++++++++++++++" + input.readLine());
|
|
while ((line = input.readLine()) != null) {
|
|
System.out.println(line); //<-- Parse data here.
|
|
String [] words = line.split(" ");
|
|
String [] procInfo = new String[10];
|
|
if (words[0].contains(processNm)){
|
|
System.out.println("+++++++++++line++++++++++++++++++++++"+line);
|
|
int nCnt = 0;
|
|
for(String item : words){
|
|
if (item.equals(""))
|
|
continue;
|
|
System.out.print(item + " ");
|
|
procInfo[nCnt] = item;
|
|
nCnt++;
|
|
}
|
|
|
|
System.out.println("Process Name : "+ procInfo[0]);
|
|
System.out.println("Process ID : "+ procInfo[1]);
|
|
System.out.println("Memory Usage : "+ procInfo[4]);
|
|
pId = procInfo[1];
|
|
}
|
|
}
|
|
input.close();
|
|
} catch (Exception err) {
|
|
err.printStackTrace();
|
|
}
|
|
|
|
return pId;
|
|
}
|
|
}
|