Skip to content

Latest commit

 

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

proc-inspector

A small Linux process and memory inspector that reads /proc directly instead of shelling out to ps, top, or free. Includes a TCP client/server pair so stats can be queried over the network.

The Why

Most beginner "system monitor" scripts just parse the output of ps/free. This project skips that layer and reads the same files the kernel exposes to those tools, to actually practice:

  • Process lifecycle: reading process state, parent/child relationships, and computing process uptime from /proc/[pid]/stat's starttime field and /proc/uptime.
  • Virtual memory: distinguishing VmSize (virtual) from VmRSS (resident/physical) per-process, and deriving used/free/cached from /proc/meminfo.
  • Sockets: a hand-written TCP server/client using Python's socket module directly (no web framework), with a minimal line-delimited JSON protocol.

Usage

Local CLI

python3 cli.py mem              # system-wide memory summary
python3 cli.py list             # list all running processes
python3 cli.py process <pid>    # detailed info for one process

Running python3 cli.py mem on linux terminal image

Running python3 cli.py list on linux terminal

image

Over the network

Start the server:

python3 server.py --host 0.0.0.0 --port 9000

Query it from a client (same machine or another one):

python3 client.py --cmd mem --host <server-ip> --port 9000
python3 client.py --cmd process --pid 1234 --host <server-ip> --port 9000
python3 client.py --cmd list --host <server-ip> --port 9000

How it works

File Purpose
proc_reader.py Core parsing logic for /proc/[pid]/status, /proc/[pid]/stat, /proc/[pid]/cmdline, /proc/meminfo, /proc/uptime
cli.py Local command-line interface built on proc_reader.py
server.py TCP server exposing the same stats over a JSON-over-socket protocol
client.py TCP client for querying the server

No third-party dependencies -- everything uses the Python standard library (os, socket, json, argparse).

Notes / limitations

  • Some fields (e.g. VmRSS for zombie processes, or any field for processes owned by another user) may be empty or require elevated permissions to read -- this is standard Linux behavior, not a bug, and is handled gracefully (skipped rather than crashing).
  • The socket protocol is intentionally minimal (newline-delimited JSON, no auth/TLS) since the goal here is demonstrating socket programming fundamentals, not building a production monitoring service.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages