pub fn currently_running() -> Result<RunningProcs> {
        let mut procs = ProcMap::new();
        let mut errors = vec![];
        let is_digit = Regex::new(r"^[0-9]+$").unwrap();
        for entry in fs::read_dir("/proc")? {
            if entry.is_err() {
                continue;
            }
            let entry = entry.unwrap();
            if let Some(fname) = entry.path().file_name() {
                fname
                    .to_str()
                    .map(|fname| {
                        if !is_digit.is_match(fname) {
                            // we only care about the pid files
                            return;
                        }
                        match pid::Process::from_pid(fname) {
                            Ok(prc) => {
                                procs.insert(prc.stat.pid, prc);
                            }
                            Err(e) => errors.push(e),
                        }
                    })
                    .unwrap(); // all /proc filenames should be legal
            }
        }
        if errors.is_empty() {
            Ok(RunningProcs(procs))
        } else {
            Err(LoadProcsError {
                procs: RunningProcs(procs),
                errors,
            }
            .into())
        }
    }
/// Load the currently running processes from /proc/[pid]/*
Load the currently running processes from /proc/[pid]
Load the currently running processes from / proc / [ pid ]
pub fn currently_running() -> Result<RunningProcs> {
        let mut procs = ProcMap::new();
        let mut errors = vec![];
        let is_digit = Regex::new(r"^[0-9]+$").unwrap();
        for entry in fs::read_dir("/proc")? {
            if entry.is_err() {
                continue;
            }
            let entry = entry.unwrap();
            if let Some(fname) = entry.path().file_name() {
                fname
                    .to_str()
                    .map(|fname| {
                        if !is_digit.is_match(fname) {
                            // we only care about the pid files
                            return;
                        }
                        match pid::Process::from_pid(fname) {
                            Ok(prc) => {
                                procs.insert(prc.stat.pid, prc);
                            }
                            Err(e) => errors.push(e),
                        }
                    })
                    .unwrap(); // all /proc filenames should be legal
            }
        }
        if errors.is_empty() {
            Ok(RunningProcs(procs))
        } else {
            Err(LoadProcsError {
                procs: RunningProcs(procs),
                errors,
            }
            .into())
        }
    }
pub fn currently_running ( ) -> Result < RunningProcs > { let mut procs = ProcMap :: new ( ) ; let mut errors = vec ! [ ] ; let is_digit = Regex :: new ( r"^[0-9]+$" ) . unwrap ( ) ; for entry in fs :: read_dir ( " " ) ? { if entry . is_err ( ) { continue ; } let entry = entry . unwrap ( ) ; if let Some ( fname ) = entry . path ( ) . file_name ( ) { fname . to_str ( ) . map ( | fname | { if ! is_digit . is_match ( fname ) { // we only care about the pid files return ; } match pid :: Process :: from_pid ( fname ) { Ok ( prc ) => { procs . insert ( prc . stat . pid , prc ) ; } Err ( e ) => errors . push ( e ) , } } ) . unwrap ( ) ; // all /proc filenames should be legal } } if errors . is_empty ( ) { Ok ( RunningProcs ( procs ) ) } else { Err ( LoadProcsError { procs : RunningProcs ( procs ) , errors , } . into ( ) ) } }
Load the currently running processes from /proc/[pid]
Load the currently running processes from / proc / [ pid ]