Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/matsumotory/procps-sys
Interface procps library from Rust
https://github.com/matsumotory/procps-sys
binding libprocps procps rust
Last synced: about 2 months ago
JSON representation
Interface procps library from Rust
- Host: GitHub
- URL: https://github.com/matsumotory/procps-sys
- Owner: matsumotory
- License: mit
- Created: 2017-05-04T16:23:14.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-12-01T06:38:12.000Z (about 6 years ago)
- Last Synced: 2024-10-18T18:16:46.204Z (3 months ago)
- Topics: binding, libprocps, procps, rust
- Language: Rust
- Size: 35.2 KB
- Stars: 10
- Watchers: 5
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# procps-sys
This library lets you a fully interface `procps`, which provides an API for Linux' `/proc` filesystem.
You can find it on [crates.io](https://crates.io/crates/procps-sys/).
## Dependency
- ubuntu 16.04
```
sudo apt-get install libprocps4-dev
```## Example
```rust
extern crate procps_sys;use procps_sys::readproc::*;
use std::ffi::CStr;
use std::ptr::null_mut;fn main() {
unsafe {
// intialize query for process list
let proctab = openproc(
/* fills cmdline line attribute */
PROC_FILLSTAT | PROC_FILLSTATUS | PROC_FILLCOM,
);// go through all processes
let mut optional = Some(readproc(proctab, null_mut()));while let Some(p) = optional {
if p.is_null() {
optional = None;
} else {
let env_str = if !(*p).cmdline.is_null() && !(*(*p).cmdline).is_null() {
CStr::from_ptr(*(*p).cmdline).to_string_lossy().into_owned()
} else {
"null".to_string()
};
println!(
"pid: {} vm_size: {} cmdline: {}",
(*p).tid,
(*p).vm_size,
env_str
);
optional = Some(readproc(proctab, null_mut()));
}
freeproc(p);
}
closeproc(proctab);
}
}
``````c
#include
#include
#includeint main(int argc, char **argv) {
PROCTAB *proc = openproc(PROC_FILLMEM | PROC_FILLSTAT | PROC_FILLSTATUS | PROC_FILLCOM);
proc_t *proc_info;while ((proc_info = readproc(proc, NULL)) != NULL) {
if (proc_info->cmdline != NULL) {
printf("%20s:\t%5ld\t%5lld\t%5lld\t%20s\n", proc_info->cmd, proc_info->resident,
proc_info->utime, proc_info->stime, proc_info->cmdline[0]);
freeproc(proc_info);
}
}closeproc(proc);
}
```