#![crate_name = "sysinfo"]
#![crate_type = "lib"]
#![crate_type = "rlib"]
#![deny(missing_docs)]
#![deny(intra_doc_link_resolution_failure)]
#![allow(unknown_lints)]
#[macro_use]
extern crate cfg_if;
#[cfg(not(any(target_os = "unknown", target_arch = "wasm32")))]
extern crate libc;
extern crate rayon;
#[macro_use]
extern crate doc_comment;
#[cfg(test)]
doctest!("../README.md");
cfg_if! {
if #[cfg(target_os = "macos")] {
mod mac;
use mac as sys;
} else if #[cfg(windows)] {
mod windows;
use windows as sys;
extern crate winapi;
extern crate ntapi;
} else if #[cfg(unix)] {
mod linux;
use linux as sys;
} else {
mod unknown;
use unknown as sys;
}
}
pub use common::{AsU32, DiskType, NetworksIter, Pid, RefreshKind};
pub use sys::{Component, Disk, NetworkData, Networks, Process, ProcessStatus, Processor, System};
pub use traits::{
ComponentExt, DiskExt, NetworkExt, NetworksExt, ProcessExt, ProcessorExt, SystemExt,
};
#[cfg(feature = "c-interface")]
pub use c_interface::*;
pub use utils::get_current_pid;
#[cfg(feature = "c-interface")]
mod c_interface;
mod common;
mod debug;
mod system;
mod traits;
mod utils;
pub fn set_open_files_limit(mut _new_limit: isize) -> bool {
#[cfg(all(not(target_os = "macos"), unix))]
{
if _new_limit < 0 {
_new_limit = 0;
}
let max = sys::system::get_max_nb_fds();
if _new_limit > max {
_new_limit = max;
}
if let Ok(ref mut x) = unsafe { sys::system::REMAINING_FILES.lock() } {
let diff = max - **x;
**x = _new_limit - diff;
true
} else {
false
}
}
#[cfg(any(not(unix), target_os = "macos"))]
{
false
}
}
#[repr(C)]
#[derive(Clone, PartialEq, PartialOrd, Debug, Copy)]
pub enum Signal {
Hangup = 1,
Interrupt = 2,
Quit = 3,
Illegal = 4,
Trap = 5,
Abort = 6,
Bus = 7,
FloatingPointException = 8,
Kill = 9,
User1 = 10,
Segv = 11,
User2 = 12,
Pipe = 13,
Alarm = 14,
Term = 15,
Stklft = 16,
Child = 17,
Continue = 18,
Stop = 19,
TSTP = 20,
TTIN = 21,
TTOU = 22,
Urgent = 23,
XCPU = 24,
XFSZ = 25,
VirtualAlarm = 26,
Profiling = 27,
Winch = 28,
IO = 29,
Power = 30,
Sys = 31,
}
#[repr(C)]
#[derive(Default, Debug, Clone)]
pub struct LoadAvg {
pub one: f64,
pub five: f64,
pub fifteen: f64,
}
#[cfg(test)]
mod test {
use super::*;
#[test]
fn check_memory_usage() {
let mut s = ::System::new();
s.refresh_all();
assert_eq!(
s.get_processes()
.iter()
.all(|(_, proc_)| proc_.memory() == 0),
false
);
}
}