• Stars
    star
    145
  • Rank 254,087 (Top 6 %)
  • Language
    Ruby
  • License
    Apache License 2.0
  • Created about 15 years ago
  • Updated 9 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A cross-platform Ruby interface for gathering process information on your operating system

Ruby

sys-proctable

Description

A Ruby interface for gathering process information.

Prerequisites

  • ffi
  • rspec (development only)
  • rake (development only)
  • rubocop (development only)

Supported Platforms

  • Windows 2000 or later
  • Linux 2.6+
  • FreeBSD
  • DragonflyBSD
  • Solaris 8+
  • OS X 10.7+
  • AIX 5.3+

Installation

gem install sys-proctable

For version 1.1.5 or earlier, you may need to specify a platform in some cases. For example:

gem install sys-proctable --platform mswin32 # Windows
gem install sys-proctable --platform sunos   # Solaris
gem install sys-proctable --platform linux   # Linux
gem install sys-proctable --platform freebsd # FreeBSD
gem install sys-proctable --platform darwin  # OS X

Adding the trusted cert

gem cert --add <(curl -Ls https://raw.githubusercontent.com/djberg96/sys-proctable/main/certs/djberg96_pub.pem)

Synopsis

require 'sys/proctable'
include Sys

# Everything
ProcTable.ps{ |p|
  puts p.pid.to_s
  puts p.comm
  # ...
}

# Just one process
s = ProcTable.ps(pid: 2123)
puts s.pid.to_s
puts s.comm
# ...

# Return the results as an array of ProcTableStructs
a = ProcTable.ps
a.each do |p|
  puts p.pid
  # ...
end

Notes

Various platforms support different options. Mostly this is to let you skip the collection of certain bits of information in order to improve speed and/or reduce memory. For example on Linux you can do this to skip the collection of smaps information:

Sys::ProcTable.ps(smaps: false)

Windows users may send a host name to get process information from a different host. This relies on the WMI service running.

Sys::ProcTable.ps(host: some_host)

Known Issues

FreeBSD

A kvm interface is used. That means the owner of the process using the sys-proctable library needs to be a member of the kvm group (or root).

Bundler

For version 1.1.5 or earlier, Bundler seems to have trouble installing the proper gem because of the platform specific gem names. To deal with that, run this command first:

bundle config specific_platform true

You should not have to do this for version 1.2.0 or later.

Solaris

The cmdline member on Solaris is limited to 80 characters unless you (or your program) own the process. This is a Solaris design flaw/feature.

OS X

The libproc interface is used. That means you will only get list of processes that you have access to. To get a full listing, run as root.

Future Plans

Support for Solaris will probably be dropped in the next major release.

Acknowledgements

This library was originally based on the Perl module Proc::ProcessTable by Dan Urist. Many ideas, as well as large chunks of code, were taken from his work. So, a big THANK YOU goes out to Dan Urist.

A big thanks also goes out to Mike Hall who was very helpful with ideas, logic and testing.

Thanks also go to Sean Chittenden for providing an account on one of his FreeBSD machines. This is how the FreeBSD support was (initially) added.

Thanks go to James Hranicky for providing a patch that grabs name, eid, euid, gid and guid info in the Linux version, along with some general debugging help.

Thanks go to David Felstead for the original OS X code. Thanks also go to Matthias Zirnstein for adding the original cmdline support for OS X.

Finally I'd like to thank all the folks who have submitted bug reports and/or patches.

Help Wanted

I do not have access to all platforms. If your platform is not supported then you will need to either submit a patch or give me a remote account on a box with a compiler so that I can write the code.

More documentation

See the documentation under the 'doc' directory for more information, including platform specific notes and issues.

License

Apache-2.0

Copyright

(C) 2003-2023 Daniel J. Berger All Rights Reserved.

Author

Daniel J. Berger

More Repositories

1

sys-filesystem

A Ruby library for getting filesystem information
Ruby
103
star
2

net-ping

A collection of classes that provide different ways to ping computers.
Ruby
101
star
3

sys-cpu

A Ruby interface for getting CPU information
Ruby
43
star
4

ptools

Extra methods (power tools) for the File class for Ruby
Ruby
38
star
5

sys-uname

A Ruby interface for getting operating system information.
Ruby
28
star
6

rack-auth-kerberos

A Rack library for authenticating users via Kerberos
Ruby
19
star
7

interface

Java style interfaces for Ruby
Ruby
19
star
8

strongtyping

Strong typing for Ruby
C
12
star
9

gis-distance

Calculate geographic distances using latitude and longitude
Ruby
12
star
10

sys-uptime

A Ruby interface for getting system uptime information
Ruby
12
star
11

pr-zlib

A pure Ruby implementation of the zlib library
Ruby
12
star
12

sys-admin

A Ruby library that presents a unified, cross-platform replacement for the Etc module
Ruby
12
star
13

io-extra

Additional methods for the IO class on Unix platforms
C
12
star
14

highlander

Ruby library to prevent multiple instances of the same process from running
Ruby
11
star
15

getopt

Simple command line option parsing for Ruby
Ruby
10
star
16

file-find

A better way to find files with Ruby
Ruby
10
star
17

attempt

A thin wrapper for begin + rescue + sleep + retry.
Ruby
9
star
18

html-table

An interface for generating HTML tables with Ruby, with some rules enforcement
Ruby
8
star
19

linux-kstat

A Ruby library for gathering Linux kernel statistics out of /proc/stat
Ruby
8
star
20

solaris-kstat

A Ruby interface for the kstat (kernel statistics) library on Solaris
Ruby
7
star
21

mail-sympa

A Ruby interface for the Sympa mailing list management software
Ruby
6
star
22

mkmf-lite

A lighter version of mkmf designed for use a library
Ruby
6
star
23

pathname2

An alternate implementation of the Pathname class
Ruby
6
star
24

proc-wait3

Adds the wait3, wait4, waitid, pause, sigsend, and getrusage methods to the Ruby Process module
C
6
star
25

use

A Ruby library that allows you to selectively mixin methods from a module
Ruby
5
star
26

file-temp

An alternative for generating temporary files with Ruby
Ruby
5
star
27

win32-open3

An open3 implementation for Ruby 1.8.x on MS Windows
Ruby
4
star
28

win32-sspi

Yet another Ruby SSPI module
Ruby
4
star
29

crypt-rot13

A Ruby interface for everyone's favorite encryption scheme
Ruby
4
star
30

ez-email

A very easy interface for sending simple text based emails with Ruby
Ruby
4
star
31

archive-tar-external

A Ruby tar and compression library that wraps external system calls
Ruby
4
star
32

hashslice

A Ruby library that adds hash slicing to the core Hash class
Ruby
3
star
33

enumerable-extra

Modified Enumerable methods designed to make list comprehensions easier
Ruby
3
star
34

dbi-dbrc

A database resource control interface for Ruby that lets you avoid hard coding your passwords
Ruby
3
star
35

oracle-model-generator

A Ruby library for generating ActiveRecord models from Oracle tables or views
Ruby
3
star
36

deckbuilder

Proof of concept for a Rails deckbuilding app
Ruby
2
star
37

netrunner-tracker

A web app for tracking games of Android: Netrunner
Ruby
2
star
38

azure-sastoken

A Ruby library for generating SAS tokens.
Ruby
2
star
39

apple-system-logger

A Ruby interface for the Apple system logger
Ruby
2
star
40

net-proto

A Ruby interface for getting network protocol information
Ruby
2
star
41

crystal-uname

A Crystal library for getting operating system information
Crystal
2
star
42

win32-thread

A Ruby interface to native threads on MS Windows
Ruby
2
star
43

sys-memory

A Ruby library for collecting memory information on your system
Ruby
2
star
44

net-tnsping

A Ruby library that simulates the Oracle tnsping utility
Ruby
2
star
45

sctp-socket

Ruby bindings for SCTP sockets
C
2
star
46

union

A Ruby analogue of a C union
Ruby
2
star
47

win32-xpath

Custom File.expand_path for Windows
Ruby
2
star
48

secure-manifest

A Rubygems plugin that validates gem contents against its manifest file
Ruby
1
star
49

berger_spec

My own personal Ruby test suite
Ruby
1
star
50

crystal-ptools

A port of my ptools Ruby library over to Crystal
Crystal
1
star
51

notation

A Ruby library that lets you use symbols as method names
Ruby
1
star
52

solaris-file

A specialized File class for Solaris that adds ACL support and door methods
Ruby
1
star
53

crypt-fog

Very simple encryption for Ruby
Ruby
1
star
54

sys-host

A Ruby library that provides hostname and IP address information
C
1
star
55

facade

A Ruby library that provides an easy way to implement the facade pattern in your classes
Ruby
1
star
56

ansiblestuff

Temporary Repo to futz with my own Ansible playbooks
1
star
57

final

A library for simulating the effects of final in Ruby
Ruby
1
star