Skip to content

Instantly share code, notes, and snippets.

@anton-matosov
Created July 25, 2024 01:31
Show Gist options
  • Save anton-matosov/805a4832a1ba27d84306708fd35b31a9 to your computer and use it in GitHub Desktop.
Save anton-matosov/805a4832a1ba27d84306708fd35b31a9 to your computer and use it in GitHub Desktop.
Cross platform environment variable inspector (tested on macOS Sonoma 14.5 and python 3.12)
#!/usr/bin/env python
import psutil
import sys
if len(sys.argv) >= 2:
pid = int(sys.argv[1])
else:
import questionary
answer = questionary.select(
"Which process to inspect?",
choices=[
f'{proc.name()} | {proc.pid}' for proc in psutil.process_iter(["pid", "name"])
]).ask() # returns value of selection
pid = int(answer.split(" | ")[1])
proc = psutil.Process(pid)
env = proc.environ()
for key, value in env.items():
print(f"{key}={value}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment