28 releases

0.14.8 Apr 24, 2024
0.14.6 Mar 13, 2024
0.14.2 Sep 18, 2023
0.14.0 Jul 6, 2023
0.1.0 Aug 22, 2016

#22 in Unix APIs

Download history 7552/week @ 2024-02-15 8580/week @ 2024-02-22 8734/week @ 2024-02-29 9901/week @ 2024-03-07 10120/week @ 2024-03-14 10965/week @ 2024-03-21 9290/week @ 2024-03-28 10066/week @ 2024-04-04 9800/week @ 2024-04-11 9547/week @ 2024-04-18 10002/week @ 2024-04-25 10407/week @ 2024-05-02 9500/week @ 2024-05-09 9634/week @ 2024-05-16 9583/week @ 2024-05-23 8911/week @ 2024-05-30

39,304 downloads per month
Used in 101 crates (16 directly)

MIT license

110KB
2K SLoC

Build Status codecov

libproc-rs

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

Add it to your project's Cargo.toml:

libproc = "0.14.4"

And then use it in your code:

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()
}

You can find the latest published release on crates.io

You can find the browseable docs for the latest release on docs.rs.

NOTE: master branch (code and docs) can differ from those docs prior to a new release.

Minimum rust version

The minimum rust version required is currently: 1.74.1 and this is tested in CI and must pass.

Test Matrix

The Github Actions CI matrix is:

rust versions:

  • stable (must pass)
  • beta (must pass)
  • 1.74.1 (currently the minimum rust version supported) (must pass)
  • nightly (allowed to fail)

on the following platforms:

  • ubuntu-latest
  • macos-11 (Big Sur)
  • macos-12 (Monterey)
  • macos-13 (Ventura)
  • macos-14 (Sonoma)

Mac OS X Versions

Calls were added to libproc in 10.9 (Mavericks) and they are under a rust "feature" switch called "macosx_10_9". The default build includes the "macosx_10_9" feature.

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

Examples

Two simple examples are included to show libproc-rs working.

  • 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.

These can be ran thus: sudo cargo run --example procinfo or sudo cargo run --example dmesg

Contributing

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

Experiment in OSS funding

I am exploring the ideas around Open Source Software funding from RadWorks Foundation via the Drips Project

This project is in Drips here

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

Build and Test Locally

If you're feeling lucky today, start with make

cargo test will build and test as usual.

However, as some functions need to be run as root to work, CI tests are run 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.

Using "act" to run GH Actions CI workflows locally

If you develop on macos but want to ensure code builds and tests pass on linux while making changes, you can use the act tool to run the Github Actions Workflows on the test matrix.

Just install "act" (brew install act) (previously install docker if you don't have it already, and make sure the daemon is running) then run act at the command line

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.

LICENSE

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

Dependencies

~0–9MB
~77K SLoC