A simple cross-platform Python script to list running processes with memory usage, optional Windows session lookup, and interactive sorting.
- Lists processes with PID, session name (Windows, optional), memory usage, and state.
- Sort by memory (default), PID, or name.
- Interactive prompt to choose ascending/descending order when run in a terminal.
- CLI flags to control sorting, order, and limit output.
- Python 3.8+ (tested with Python 3.11/3.13)
- Python packages (see
requirements.txt):- psutil
- tabulate
- pywin32 (optional, Windows only, for session/username lookup)
Open PowerShell in the project folder (where taskmgr.py and requirements.txt live).
- Create and activate a virtual environment
python -m venv .venv
.venv\Scripts\Activate.ps1If activation is blocked by policy, run:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser- Upgrade pip and install requirements
python -m pip install --upgrade pip
pip install -r .\requirements.txtRun the script (interactive prompt appears if in a terminal):
python taskmgr.pyCommand-line options
--sort {memory,pid,name}— Field to sort by (default: memory)--order {asc,desc}— Explicit sort order (overrides interactive choice)--reverse— Reverse sort order (alias)--no-prompt— Don't prompt interactively; use defaults or provided flags--top N— Show only the top N entries after sorting
Examples
- Default (interactive prompt for asc/desc):
python taskmgr.py- Non-interactive, ascending by memory (default):
python taskmgr.py --no-prompt- Show top 5 by memory descending:
python taskmgr.py --order desc --top 5 --no-prompt- Sort by PID ascending:
python taskmgr.py --sort pid --no-prompt- On Windows, installing
pywin32enables session/username lookups. If not present the script will displayN/Afor session names. - Running
pipx install --editable .will fail without apyproject.tomlorsetup.py. Use the virtualenv approach above instead.
Activate.ps1 cannot be loaded→ run PowerShell as Administrator or runSet-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser.Permission deniedinstalling packages → use a virtualenv or run PowerShell as Administrator.- If
pipinstalls to a different Python, runpython -m pip install ...to ensure packages are installed for the same interpreter you run the script with.
- Add CPU usage column and sorting by CPU
- Add filtering options (by name, state)
- Add a packaged CLI with
pyproject.tomlforpipxinstallation
If you'd like, I can:
- Run the installation commands in your terminal now
- Add a
pyproject.tomlsopipx install --editable .works - Add CPU usage or owner username columns
Tell me which and I will proceed.