1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
// // Sysinfo // // Copyright (c) 2015 Guillaume Gomez // //! `sysinfo` is a crate used to get a system's information. //! //! Before any attempt to read the different structs' information, you need to update them to //! get up-to-date information. //! //! # Examples //! //! ``` //! use sysinfo::{ProcessExt, SystemExt}; //! //! let mut system = sysinfo::System::new(); //! //! // First we update all information of our system struct. //! system.refresh_all(); //! //! // Now let's print every process' id and name: //! for (pid, proc_) in system.get_process_list() { //! println!("{}:{} => status: {:?}", pid, proc_.name(), proc_.status()); //! } //! //! // Then let's print the temperature of the different components: //! for component in system.get_components_list() { //! println!("{:?}", component); //! } //! //! // And then all disks' information: //! for disk in system.get_disks() { //! println!("{:?}", disk); //! } //! //! // And finally the RAM and SWAP information: //! println!("total memory: {} kB", system.get_total_memory()); //! println!("used memory : {} kB", system.get_used_memory()); //! println!("total swap : {} kB", system.get_total_swap()); //! println!("used swap : {} kB", system.get_used_swap()); //! ``` #![crate_name = "sysinfo"] #![crate_type = "lib"] #![crate_type = "rlib"] #![deny(missing_docs)] //#![deny(warnings)] #![allow(unknown_lints)] #[macro_use] extern crate cfg_if; #[cfg(not(target_os = "unknown"))] 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, Pid, RefreshKind}; pub use sys::{Component, Disk, DiskType, NetworkData, Process, ProcessStatus, Processor, System}; pub use traits::{ComponentExt, DiskExt, NetworkExt, 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 component; mod process; mod processor; mod system; mod traits; mod utils; /// An enum representing signal on UNIX-like systems. #[repr(C)] #[derive(Clone, PartialEq, PartialOrd, Debug, Copy)] pub enum Signal { /// Hangup detected on controlling terminal or death of controlling process. Hangup = 1, /// Interrupt from keyboard. Interrupt = 2, /// Quit from keyboard. Quit = 3, /// Illegal instruction. Illegal = 4, /// Trace/breakpoint trap. Trap = 5, /// Abort signal from C abort function. Abort = 6, // IOT trap. A synonym for SIGABRT. // IOT = 6, /// Bus error (bad memory access). Bus = 7, /// Floating point exception. FloatingPointException = 8, /// Kill signal. Kill = 9, /// User-defined signal 1. User1 = 10, /// Invalid memory reference. Segv = 11, /// User-defined signal 2. User2 = 12, /// Broken pipe: write to pipe with no readers. Pipe = 13, /// Timer signal from C alarm function. Alarm = 14, /// Termination signal. Term = 15, /// Stack fault on coprocessor (unused). Stklft = 16, /// Child stopped or terminated. Child = 17, /// Continue if stopped. Continue = 18, /// Stop process. Stop = 19, /// Stop typed at terminal. TSTP = 20, /// Terminal input for background process. TTIN = 21, /// Terminal output for background process. TTOU = 22, /// Urgent condition on socket. Urgent = 23, /// CPU time limit exceeded. XCPU = 24, /// File size limit exceeded. XFSZ = 25, /// Virtual alarm clock. VirtualAlarm = 26, /// Profiling time expired. Profiling = 27, /// Windows resize signal. Winch = 28, /// I/O now possible. IO = 29, // Pollable event (Sys V). Synonym for IO //Poll = 29, /// Power failure (System V). Power = 30, /// Bad argument to routine (SVr4). Sys = 31, } #[cfg(test)] mod test { use traits::{ProcessExt, SystemExt}; #[test] fn check_memory_usage() { let mut s = ::System::new(); s.refresh_all(); assert_eq!( s.get_process_list() .iter() .all(|(_, proc_)| proc_.memory() == 0), false ); } }