Created
April 16, 2013 14:05
-
-
Save chitacan/5396157 to your computer and use it in GitHub Desktop.
get process start time from proc filesystem in java.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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