Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.io.BufferedReader;

import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static int getPid(String tag) {
        Process p;
        try {
            p = Runtime.getRuntime().exec("ps ");
            BufferedReader bufferedReader2 = new BufferedReader(new InputStreamReader(p.getInputStream()));
            String line;
            while ((line = bufferedReader2.readLine()) != null) {
                if (line.contains(tag)) {
                    return Integer.parseInt(line.split("\\s+")[1]);
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

        return -1;
    }
}