Skip to main content

A small tool for running and tracking background processes over a local TCP port.

Project description

procsock

A small tool for running and tracking background processes over a local TCP port.

It is not a terminal multiplexer and does not use PTYs. It launches plain child processes, redirects their stdin/stdout/stderr to files, and lets clients query whether a process is still running or has finished.

Overview

procsock consists of two pieces:

  • a server
  • a client that connects over a local TCP port when the server is available

The server accepts JSON-RPC requests to start and inspect processes. Each process is started with:

  • argv
  • client's current working directory
  • client's current environment
  • optional stdin file
  • optional stdout file
  • optional stderr file

When not specified, stdin/stdout/stderr default to os.devnull.

The launcher returns a process identifier:

  • on Unix, it is the process ID
  • on Windows/NT, it is the process handle

The server keeps the process state in memory only. If the server exits or restarts, all state is lost.

Example session

Start server:

procsock server --port 9000

Launch process:

procsock launch \
  --port 9000 \
  --stdin /tmp/in.txt \
  --stdout /tmp/out.txt \
  --stderr /tmp/err.txt \
  -- /usr/bin/python3 -c 'print("hello")'

List:

procsock list --port 9000

Terminate:

procsock terminate --port 9000 12345

How it works

  1. Start the server in the foreground.
  2. The server binds a local TCP port.
  3. A client connects and sends JSON-RPC commands.
  4. The server launches child processes with ctypes-unicode-proclaunch.
  5. Each launched process is started from a dedicated launcher thread.
  6. That launcher thread uses the client's current working directory as the process working directory.
  7. This is implemented with a small synchronized TempCwd helper class exposing __enter__ and __exit__.
  8. A waiter thread waits for process completion and updates the in-memory process status on exit.
  9. The client can list the status of all processes or terminate a process.
  10. If the server exits, managed children are terminated, and the in-memory process state is lost.

Commands

launch

Launch a new child process via ctypes-unicode-proclaunch.

For the CLI, the launched process inherits the current environment of the procsock launch client process.

For each launched process:

  • stdin is opened from the requested file path, typically read-only
  • stdout is opened to the requested file path
  • stderr is opened to the requested file path
  • any unspecified stdin/stdout/stderr path defaults to os.devnull

Behavior should match normal process redirection semantics:

  • stdin: if a path is provided, it must already exist
  • stdout: if a path is provided, open with create/truncate behavior
  • stderr: if a path is provided, open with create/truncate behavior
  • parent directories are not created automatically

Request:

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "launch",
  "params": {
    "argv": ["/bin/sh", "-c", "echo hello; sleep 2"],
    "cwd": "/tmp",
    "stdin_path": "/tmp/in.txt",
    "stdout_path": "/tmp/out.txt",
    "stderr_path": "/tmp/err.txt"
  }
}

Response:

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "pid": 12345,
    "argv": ["/bin/sh", "-c", "echo hello; sleep 2"],
    "cwd": "/tmp",
    "stdin_path": "/tmp/in.txt",
    "stdout_path": "/tmp/out.txt",
    "stderr_path": "/tmp/err.txt",
    "finished": false,
    "started_at": 1760000000.0,
    "finished_at": null,
    "exit_code": null
  }
}

list

Return the status of all known in-memory processes.

Request:

{
  "jsonrpc": "2.0",
  "id": 2,
  "method": "list",
  "params": {}
}

Response:

{
  "jsonrpc": "2.0",
  "id": 2,
  "result": [
    {
      "pid": 12345,
      "argv": ["/bin/sh", "-c", "echo hello; sleep 2"],
      "cwd": "/tmp",
      "stdin_path": "/tmp/in.txt",
      "stdout_path": "/tmp/out.txt",
      "stderr_path": "/tmp/err.txt",
      "finished": false,
      "started_at": 1760000000.0,
      "finished_at": null,
      "exit_code": null
    }
  ]
}

terminate

Terminate a process with SIGTERM.

Contributing

Contributions are welcome! Please submit pull requests or open issues on the GitHub repository.

License

This project is licensed under the MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

procsock-0.1.0a2.tar.gz (8.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

procsock-0.1.0a2-py2.py3-none-any.whl (8.6 kB view details)

Uploaded Python 2Python 3

File details

Details for the file procsock-0.1.0a2.tar.gz.

File metadata

  • Download URL: procsock-0.1.0a2.tar.gz
  • Upload date:
  • Size: 8.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.13

File hashes

Hashes for procsock-0.1.0a2.tar.gz
Algorithm Hash digest
SHA256 5a667c17de1631d32e975fce3481e3675252618f2181a551a898d76e8d1e930a
MD5 927199a8cf0ecd2a01c026b2f52279cf
BLAKE2b-256 e85ebe725ae18f043b5c127ae760ad4197782b4de7e52a4bc9e6134317ce7a78

See more details on using hashes here.

File details

Details for the file procsock-0.1.0a2-py2.py3-none-any.whl.

File metadata

  • Download URL: procsock-0.1.0a2-py2.py3-none-any.whl
  • Upload date:
  • Size: 8.6 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.13

File hashes

Hashes for procsock-0.1.0a2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 051b3207ac707d9bbb6162e5cf2064e906cabc3a3eef2ba2ac0389696cbdcee1
MD5 9a4a5b66721711997394db95ffbe1b39
BLAKE2b-256 1d18025ce3b9b35b103f056857e8a61f47d14730e62950977bca768ff08fc198

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page