下面是通过linux命令来获取进程ID的
Process psProcess = Runtime.getRuntime().exec("sh");
DataOutputStream out = new DataOutputStream( psProcess.getOutputStream() );
InputStream is = psProcess.getInputStream();
out.writeBytes( "ps | grep 'vpnloader' | cut -c 10-14\n" );
out.writeBytes( "ps\n" );
out.flush();
try {
psProcess.waitFor();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();}
if(is.read() != 0)
{
byte firstByte = (byte)is.read();
int available = is.available();
byte[] characters = new byte[available + 1];
characters[0] = firstByte;
is.read( characters, 1, available );
String re = new String( characters );
}
Process psProcess = Runtime.getRuntime().exec("sh");
DataOutputStream out = new DataOutputStream( psProcess.getOutputStream() );
InputStream is = psProcess.getInputStream();
out.writeBytes( "ps | grep 'vpnloader' | cut -c 10-14\n" );
out.writeBytes( "ps\n" );
out.flush();
try {
psProcess.waitFor();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();}
if(is.read() != 0)
{
byte firstByte = (byte)is.read();
int available = is.available();
byte[] characters = new byte[available + 1];
characters[0] = firstByte;
is.read( characters, 1, available );
String re = new String( characters );
}