Fd泄露跟踪

查询进程的fd的使用情况:

int pid = android.os.Process.myPid();

String command = "/proc/" + pid + "/fd";

File file = new File(command);

File[] files = file.listFiles();

int length = files.length;

try {

    Process p =  Runtime.getRuntime().exec("ls -l " + command);

    InputStream is = p.getInputStream();

    BufferedReader reader = new BufferedReader(new InputStreamReader(is));

    String line;

    StringBuilder result = new StringBuilder();

    while ((line = reader.readLine()) != null) {

        result.append(line + "\n");

    }

    p.waitFor();

    is.close();

    reader.close();

    p.destroy();

} catch (Exception e) {

 

}

你可能感兴趣的:(Fd泄露跟踪)