Skip to content

Instantly share code, notes, and snippets.

@chitacan
Created April 16, 2013 14:05
Show Gist options
  • Save chitacan/5396157 to your computer and use it in GitHub Desktop.
Save chitacan/5396157 to your computer and use it in GitHub Desktop.
get process start time from proc filesystem in java.
int pid = Process.myPid();
String statpath = "/proc/" + pid + "/stat";
a
try {
BufferedReader br = new BufferedReader(
new InputStreamReader(new FileInputStream(new File(statpath)))
);
String[] statline = br.readLine().split(" ");
// get system boot time
long bootime = System.currentTimeMillis() - SystemClock.elapsedRealtime();
// started_time(in milliseconds) = started_time(in jiffies) * HZ / 1000
// HZ can be found in ndk/platforms/android-9/arch-arm/usr/include/asm/param.h
// commonly HZ is 100
long started = Long.parseLong(statline[21]) * 10;
Log.d("your_tag", "started time : " + (bootime + started));
} catch (Exception e) {
e.printStackTrace();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment