static long GetSystemBootTime ()
{
if (!File.Exists ("/proc/stat"))
return -1;
string btime = null;
string line;
try {
using (StreamReader stat_file = new StreamReader ("/proc/stat", Encoding.ASCII)) {
while ((line = stat_file.ReadLine ()) != null)
if (line.StartsWith ("btime")) {
btime = line;
break;
}
}
} catch (Exception e) {
Console.Error.WriteLine ("While reading system info {0}", e);
}
if (btime == null)
return -1;
int space = btime.IndexOf (' ');
long res;
if (!Int64.TryParse (btime.Substring (space, btime.Length - space), out res))
return -1;
return res;
}