All Projects → andrewdavidmackenzie → libproc-rs

andrewdavidmackenzie / libproc-rs

Licence: MIT license
A rust library for getting information about running processes for Mac and Linux

Programming Languages

rust
11053 projects
Makefile
30231 projects

Projects that are alternatives of or similar to libproc-rs

macstats
Mac OS X Statistics - Battery, Fans, CPU
Stars: ✭ 55 (+66.67%)
Mutual labels:  darwin
mac list windows pids
Mac OS X: list all windows title and their owner process ids
Stars: ✭ 58 (+75.76%)
Mutual labels:  pid
smart-car-freescale
第九届飞思卡尔智能车参赛作品
Stars: ✭ 36 (+9.09%)
Mutual labels:  pid
static-web-server
A blazing fast and asynchronous web server for static files-serving. ⚡
Stars: ✭ 230 (+596.97%)
Mutual labels:  darwin
ClearProcesses
利用无障碍服务(AccessibilityService)批量清理后台进程
Stars: ✭ 75 (+127.27%)
Mutual labels:  processes
Corpuscles.jl
Julia package for particle physics
Stars: ✭ 25 (-24.24%)
Mutual labels:  pid
Puppy
A flexible logging library written in Swift
Stars: ✭ 64 (+93.94%)
Mutual labels:  darwin
effpi
Verified message-passing programs in Dotty
Stars: ✭ 42 (+27.27%)
Mutual labels:  processes
1ZLAB PyEspCar
1ZLab在准备挑选合适的小车来研发计算机视觉的教程时候 , 发现习惯了Python语法的我们, 在市面上找不到合适小车, 后来我们选了ESP32作为小车的控制主板, 可以使用Python对其进行交互式编程, 极大的提升了开发效率.
Stars: ✭ 78 (+136.36%)
Mutual labels:  pid
async-container
Scalable multi-thread multi-process containers for Ruby.
Stars: ✭ 58 (+75.76%)
Mutual labels:  processes
bali
Bali - Minimalist Golang build and packaging tool
Stars: ✭ 59 (+78.79%)
Mutual labels:  darwin
Puredarwin
Darwin is the Open Source core of macOS, and PureDarwin is a community project to extend Darwin into a complete, usable operating system.
Stars: ✭ 1,592 (+4724.24%)
Mutual labels:  darwin
ai for robotics
Visualizations of algorithms covered in Sebastian Thrun's excellent Artificial Intelligence for Robotics course on Udacity.
Stars: ✭ 125 (+278.79%)
Mutual labels:  pid
clock
High-resolution clock functions: monotonic, realtime, cputime.
Stars: ✭ 52 (+57.58%)
Mutual labels:  darwin
calcardbackup
calcardbackup: moved to https://codeberg.org/BernieO/calcardbackup
Stars: ✭ 67 (+103.03%)
Mutual labels:  darwin
XNU
Research into porting the XNU kernel to ARM devices.
Stars: ✭ 76 (+130.3%)
Mutual labels:  darwin
DC-Servo
Analog speed control of Brushed DC Motor
Stars: ✭ 16 (-51.52%)
Mutual labels:  pid
Quadcopter SimCon
Quadcopter Simulation and Control. Dynamics generated with PyDy.
Stars: ✭ 84 (+154.55%)
Mutual labels:  pid
FlyingCarUdacity
🛩️⚙️ 3D Planning, PID Control, Extended Kalman Filter for the Udacity Flying Car Nanodegree // FCND-Term1
Stars: ✭ 16 (-51.52%)
Mutual labels:  pid
emacs-bpr
No description or website provided.
Stars: ✭ 58 (+75.76%)
Mutual labels:  processes

Build Status codecov

libproc-rs

This is a library for getting information about running processes for Mac OS X and Linux.

Using it

extern crate libproc;
use libproc::libproc::proc_pid;

match proc_pid::pidpath(pid) {
    Ok(path) => println!("PID {}: has path {}", pid, path),
    Err(err) => writeln!(&mut std::io::stderr(), "Error: {}", err).unwrap()
}

Documentation

Online code docs

API

At the moment these methods have been implemented:

Process / PID related

pub fn listpids(proc_types: ProcType) -> Result<Vec<u32>, String> (macos) (linux)
pub fn listpidspath(proc_types: ProcType, path: &str) -> Result<Vec<u32>, String> (macos) (linux)
pub fn pidinfo<T: PIDInfo>(pid : i32, arg: u64) -> Result<T, String> (macos)
pub fn regionfilename(pid: i32, address: u64) -> Result<String, String> (macos)
pub fn pidpath(pid : i32) -> Result<String, String> (macos) (linux)
pub fn libversion() -> Result<(i32, i32), String> (macos)
pub fn name(pid: i32) -> Result<String, String> (linux) (macos)
pub fn listpidinfo<T: ListPIDInfo>(pid : i32, max_len: usize) -> Result<Vec<T::Item>, String> (macos)
pub fn pidcwd(pid: pid_t) -> Result<PathBuf, String> (linux)
pub fn cwdself() -> Result<PathBuf, String> (linux)

File and FileDescriptor related

pub fn pidfdinfo<T: PIDFDInfo>(pid : i32, fd: i32) -> Result<T, String> (macos)

PID Resource Usage related

(Added in Mac OS X 10.9 - under "macosx_10_9" feature)

pub fn pidrusage<T: PIDRUsage>(pid : i32) -> Result<T, String> (macos)

Kernel Message Buffer - kmsgbuf

pub fn kmsgbuf() -> Result<String, String>

Binaries

cargo build builds the following binaries:

  • procinfo that takes a PID as an optional argument (uses it's own pid if none supplied) and returns information about the process on stdout
  • dmesg is a version of dmesg implemented in rust that uses libproc-rs.

Rust Versions

The Github Actions CI matrix tests for rust stable, beta and nightly on all platforms

Platforms

Mac OS X (10.5 and above) and Linux.

Mac OS X Versions

Calls were aded to libproc in Mac OS X 10.7 and again in 10.9. This library can be compiled to not include those calls by using rust features to enable/disable support for those versions.

The default build is for Mac OS 10.9 or later. See:

[features]
default = ["macosx_10_9"]
macosx_10_7 = []
macosx_10_9 = ["macosx_10_7"]

in Cargo.toml

To build for versions prior to Mac OS 10.7 disable the default features by passing --no-default-features to cargo.

To build for Mac OS X 10.7 (or 10.8) you can enable that feature alone using --no-default-features --features "macosx_10_7"

Build and Test

cargo test should build and test as usual for rust projects.

However, as some functions need to be run as root to work, I run travis-CI tests as root. So, when developing in local it's best if you use sudo cargo test. NOTE: This can get you into permissions problems when switching back and for between using cargo test and sudo cargo test. To fix that run sudo cargo clean and then build or test as you prefer.

In order to have tests pass when run as root or not, some tests need to check if they are root at run-time (using our own am_root() function is handy) and avoid failing if not run as root.

Macos: clang detection and header file finding

Newer versions of bindgen have improved the detection of clang and hence macos header files. If you also have llvm/clang installed directly or via brew this may cause the build to fail saying it cannot find libproc.h. This can be fixed by setting CLANG_PATH="/usr/bin/clang" so that bindgen detects the Xcode version and hence can fidn the correct header files.

CI Testing

Continuous Integration testing has been moved from travis-ci to GitHub Actions. For details see the rust.yml GitHub Actions workflow

Input Requested

  • Suggestions for API, module re-org and cross-platform abstractions are welcome.
  • How to do error reporting? Define own new Errors, or keep simple with Strings?
  • Would like Path/PathBuf returned when it makes sense instead of String?

TODO

See the list of issues. I put the "help wanted" label where I need help from others.

  • Look at what similar methods could be implemented as a starting point on Linux
  • Complete the API on Mac OS X - figuring out all the Mac OS X / Darwin version mess....
  • Add more documentation (including samples with documentation test)
  • Add own custom error type and implement From::from to ease reporting of multiple error types in clients

LICENSE

This code is licensed under MIT license (see LICENCE).

CONTRIBUTING

You are welcome to fork this repo and make a pull request, or write an issue.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].