Track child processes.
Project description
process-tracker
Process tracker enables tracking creation of child processes.
Usage:
import process_tracker; process_tracker.install()
import os
pid1 = os.fork()
pid2 = os.fork()
pid3 = os.fork()
if pid1 and pid2 and pid3:
print(process_tracker.children())
Prints a list of tuples with (pid, create_time)
for each process.
create_time
can be used to confirm that the current process (if any) with
the given pid is the same as the original. For example:
import process_tracker
import psutil
def get_create_time(ctime):
boot_time = psutil.boot_time()
clock_ticks = os.sysconf("SC_CLK_TCK")
return boot_time + (ctime / clock_ticks)
processes = []
for pid, create_time in process_tracker.children():
try:
p = psutil.Process(pid=pid)
except psutil.NoSuchProcess:
continue
if p.create_time() == get_create_time(create_time):
processes.append(p)
# processes now has the list of active child processes
# psutil itself does a check before sensitive operations that the
# active process create time is the same as when the Process object
# was initialized.
for p in processes:
p.terminate()
Limitations
- Only tracks children spawned from dynamically-linked executables.
- Relies on
LD_PRELOAD
so will not work for setuid/setgid executables.
Development
Basic
python -m venv .venv
.venv/bin/python -m pip install tox
- Make changes
.venv/bin/python -m tox
Debugging C build
Avoids overhead of making sdist
- As above
make c-build
Debugging issues from sub-process
gdb debugging of sub-processes.
- As above
make debug
Debugging tests without rebuild
- As above
.venv/bin/python -m pip install . .[dev]
Then
pip install . && pytest
when rebuild is neededpytest
when only tests changed
Release
docker run \
-e REAL_UID=$(id -u) \
-e REAL_GID=$(id -g) \
-e PATH=/opt/python/cp37-cp37m/bin:/bin \
-v $PWD/scripts/build.sh:/build.sh \
-v $PWD:/src \
quay.io/pypa/manylinux1_x86_64 \
sh -c 'cd /src && /build.sh'
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
process-tracker-0.1.1.tar.gz
(30.0 kB
view hashes)
Built Distribution
Close
Hashes for process_tracker-0.1.1-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8f7122953765473fefefc5f0b22def9355c30fbccafee37083db6af064c90da9 |
|
MD5 | ca96285f03e8994e1525b442ed1137ae |
|
BLAKE2b-256 | 009e2a8c43ed5b7577df2c148ed57b32e57886d3310f362d116ad6519ae131d2 |