Skip to main content

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

  1. Only tracks children spawned from dynamically-linked executables.
  2. Relies on LD_PRELOAD so will not work for setuid/setgid executables.

Development

Basic

  1. python -m venv .venv
  2. .venv/bin/python -m pip install tox
  3. Make changes
  4. .venv/bin/python -m tox

Debugging C build

Avoids overhead of making sdist

  1. As above
  2. make c-build

Debugging issues from sub-process

gdb debugging of sub-processes.

  1. As above
  2. make debug

Debugging tests without rebuild

  1. As above
  2. .venv/bin/python -m pip install . .[dev]

Then

  • pip install . && pytest when rebuild is needed
  • pytest when only tests changed

Release

docker run \
    -e REAL_UID=$(id -u) \
    -e REAL_GID=$(id -g) \
    -v "$PWD/scripts/build.sh:/build.sh" \
    -v "$PWD:/src" \
    dockcross/manylinux1-x64 \
    sh -c 'cd /src && env "PATH=/opt/python/cp37-cp37m/bin:$PATH" /build.sh'

Metadata

Release files for process-tracker 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for process-tracker 0.1.2
File Size Uploaded
process-tracker-0.1.2.tar.gz 30.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for process-tracker 0.1.2
File Interpreter ABI Platform
process_tracker-0.1.2-cp37-cp37m-manylinux1_x86_64.whl CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.5+ x86-64 Details

Total release size: 112.5 kB

Release files / process-tracker-0.1.2.tar.gz

Download URL process-tracker-0.1.2.tar.gz
Size 30.4 kB
Tags Source
SHA-256 checksum
How to use checksums
c5307ea90fc36d53fa6c2034f4a1f1ed54a5e58e2ab0f203aad94b545f2fe1e3
BLAKE2b-256 checksum
How to use checksums
08cea9643120a5de4796b3a935e618b831f1d186eab31fde8f734f7ebb37df16
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.2

Release files / process_tracker-0.1.2-cp37-cp37m-manylinux1_x86_64.whl

Download URL process_tracker-0.1.2-cp37-cp37m-manylinux1_x86_64.whl
Size 82.1 kB
Tags CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.5+ x86-64
SHA-256 checksum
How to use checksums
8ca1035ca9e17fa8dbcf5f79ac6ff7ac0fb9411860f4cfd9f91533735726cd89
BLAKE2b-256 checksum
How to use checksums
1bb79a54c608b023587dc26a805fcc75bf06f4a07239dd7c8f477dad9308dc89
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.2

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.1

2 release files

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page