获取单个 运行 进程开始时间

fetching individual running process Start-Time

我正在使用下面的代码获取 Android 设备上的所有当前 运行 进程。

// Get running processes
ActivityManager manager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
List<ActivityManager.RunningAppProcessInfo> runningProcesses = manager.getRunningAppProcesses();

而且我还尝试使用以下代码从以下文件目录中的每个单独的 pid- "process id" 获取 Android 设备中的所有单独进程启动时间:"/proc/ [PID]/stat" 从 linux 获得:

public static long getStartTime(final int pid) throws IOException {

final String path = ("/proc/" + pid + "/stat");
final String stat;
final String field2End = ") ";
final String fieldSep = " ";
final BufferedReader reader = new BufferedReader(new FileReader(path));

 try {
        stat = reader.readLine();
        System.out.println("******Stat******"+ stat);
    } finally {
        reader.close();
    }

try {
        final String[] fields = stat.substring(stat.lastIndexOf(field2End)).split(fieldSep);
        final long processstartTime = .....;
        ...(change processstartTime from clock tick to seconds & return processstartTime value)...
}
}

我确实需要从以下 Linux 目录路径获取进程 StartTime:“/proc/pid/stat” 对于 Android 设备中的每个 运行 进程。此时,当我调试以下 Linux 目录路径的语句时:“/proc/[PID]/stat”,在以下代码行中:System.out.println("******Stat******"+ stat);,我得到的输出调试为:

******Stat******642 (flipboard.app) S 2848 2848 0 0 -1 4194624 126020 0 1019 0 2441 632 0 0 20 0 101 0 7040346 1079652352 7233 4294967295 1 1 0 0 0 0 4612 0 38120 4294967295 0 0 17 1 0 0 0 0 0 0 0 0

此外,我知道进程的 start_time 是以时钟滴答为单位的,因此要将其转换为秒,我需要将以下内容计算为 "start_time/hertz"。

现在的问题是,如何在“/proc/[PID]/stat”中获取 运行 进程启动时间?有人可以帮忙吗?谢谢。

个别进程时间的登录可以通过这种方式完成:

public static long getStartTime(final int pid) throws
        IOException {
    final long SYSTEM_CLK_TCK= 100; //needed as value in /proc/[PID]/stat file driectory is in clock ticks,100 is used to convert clock ticks to secs
    final int fieldStartTime = 20; //column 20 of the /proc/[PID]/stat file driectory
try {
        System.out.println("******String path******"+ path);
        stat = reader.readLine();
        System.out.println("******String stat******"+ stat);
    } finally {
        reader.close();
    }
try {
        final String[] fields = stat.substring(stat.lastIndexOf(field2End)).split(fieldSep);
        final long startTime = Long.parseLong(fields[fieldStartTime]);
        System.out.println("******fieldstarttime based on clock ticks******"+ startTime);

        return startTime * msInSec / SYSTEM_CLK_TCK;
}