1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
//! Read information about the operating system from `/proc`.

use std::str::FromStr;
use std::path::Path;

use utils::read_file;

/// Returns the system uptime in seconds.
///
/// `/proc/uptime` contains the system uptime and idle time.
pub fn uptime() -> isize {
    let data = read_file(Path::new("/proc/uptime")).unwrap();
    let numbers: Vec<&str> = data.split(' ').collect();
    let uptime: Vec<&str> = numbers[0].split('.').collect();
    FromStr::from_str(uptime[0]).unwrap()
}