Short intro
pyproc2 is Python library for reading data from /proc/ directory. Of course, it works only on Linux.
Installation
pip install pyproc2
What can it do?
Find processes
There is only one method for all filters (PID, process name, user name,etc.)
It is called find().
Here are few examples:
1. By PID:
import pyproc2
pyproc2.find(1)
2. By process name (can return multiple results)
import pyproc2
pyproc2.find("python")
3. By user name (or UID or whatever)
import pyproc2
pyproc2.find(user="root")#Replace "user" to filter by other properties
Doing things with selected process(es)
1.Sending signals Simple kill:
import pyproc2
pr=pyproc2.find("python")
pr.kill()
For other signals, pass kill() an argument.
Most common signals have defined own methods:
import pyproc2
pr=pyproc2.find("python")
pr.term() #Or stop() or cont() or whatever
2.Acessing attributes
import pyproc2
pr=pyproc2.find("python")
cpu=pr.cpu
uid=pr.uid
#etc.
3.Accessing children and parent processes
import pyproc2
pr=pyproc2.find(1)
cdr=pr.children #get all children
parent=pr.parent #get parent process
p4=pr.parentLevel(4) #equivalent of pr.parent.parent.parent.parent
kid=pr.child(3) #fourth children(sorted by PID)(negative indexes are working,too)
4.Sending data to open fds (works only as root)
import pyproc2
#simple write
pyproc2.find('bash').stdin.write('ls -la')
#simple stdout read
pyproc2.find('bash').stdout.read()
#simple stderr read
pyproc2.find('bash').stderr.read()
#write to fd
pyproc2.find('bash').fds.fd(39).write('hello')
#read from fs
pyproc2.find('bash').fds.fd(39).read()
Duplicating
r = my_process.duplicate()
This runs my_process.command using subprocess and returns result PID.
Acess predefined process sets
1.All processes
import pyproc2
rn=pyproc2.running
2.All processes, sorted by CPU rate
import pyproc2
t=pyproc2.top
3.Current process
import pyproc2
cur=pyproc2.current
License
pyproc2 is licensed under GPL License
Changelog
1.0.2
Initial
1.0.3
Improved documentation
1.0.4
Improved documentation
1.0.5
Bug fixes
1.1.0
Speed increased
1.1.1
Added owner property as equivalent to user
1.1.2
Added changelog
1.1.3
Fixed ProcessSet.kill() NotImplementedError bug
1.1.4
Added STOPPED state
1.1.5
Added current property
1.2.0
Added reading from fds and duplicating
1.2.1
Added "strict" argument in fd.py; tests failed on Debian(kthreadd)
1.2.2
Fixed OSError: too many open files. Added sudoing on duplicate() and some warnings.
Metadata
Release files for pyproc2 1.2.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pyproc2-1.2.2.tar.gz | 20.6 kB | Without provenance | Details for pyproc2-1.2.2.tar.gz |
Release files / pyproc2-1.2.2.tar.gz
| Download URL | pyproc2-1.2.2.tar.gz |
|---|---|
| Size | 20.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9c4db843fe239a3aaf54793ab03d2876a4121275e31e1c622ad05922cec86518
|
|
BLAKE2b-256 checksum How to use checksums |
eeb044d74a5f4c078dee98368b2a192ace2cf490a20c073f1f8bae8e780de96c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.7.1 importlib_metadata/4.8.1 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9
|
Security for pyproc2 1.2.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.