Processes and Network Ports
This page covers how to check running processes (PID) together with how to check the network ports those processes have opened.
Process Management (PID)
Concept
A process is a running program. Each process is assigned a unique PID (Process ID) number.
Key Commands
bash
# List all processes
ps aux
# Search for a specific process
ps aux | grep agent_app.py
# Terminate a process
kill <PID>
kill -9 <PID> # force kill
# Real-time process monitoring
top
htopHow It Is Used in monitor.sh
bash
PID=$(pgrep -f agent_app.py)
if [ -z "$PID" ]; then
echo "[ERROR] The process is not running."
exit 1
fiNetworks and Ports
Concept
A port is a door for network communication. A server opens a specific port and waits for connections (LISTEN). A client connects to that port.
Key Commands
bash
# Check open ports
ss -tulnp
# Example output
# tcp LISTEN 0 128 0.0.0.0:15034 ... python3
# Check a specific port
ss -tulnp | grep 15034Reading ss Output
| Column | Meaning |
|---|---|
| State | LISTEN = waiting for connections |
| Local Address:Port | The address:port the server has opened |
| 0.0.0.0 | Receives on all network interfaces |
Summary
| Item | Command | Notes |
|---|---|---|
| List/search processes | ps aux, ps aux | grep agent_app.py | Each process has a unique PID |
| Terminate a process | kill <PID>, kill -9 <PID> | -9 forces termination |
| Real-time monitoring | top, htop | |
| Get a PID in a script | pgrep -f agent_app.py | exit 1 if empty |
| Check open ports | ss -tulnp | LISTEN = waiting for connections, 0.0.0.0 = all interfaces |
Source: Codyssey-B1/B4-1
