| name | process_management |
| version | 1.0.0 |
| agent | system |
| risk_level | variable |
| description | Monitor, control, and manage system processes. Includes starting, stopping, and monitoring services, background jobs, and system health metrics. |
Process Management Skill
Purpose
Monitor and control system processes on the host machine. This skill enables Gorgon agents to launch applications, manage services, monitor system health, and handle background jobs.
Safety Rules
PROTECTED PROCESSES - NEVER KILL
init (PID 1)
systemd
sshd
Forge supervisor (self)
kernel threads [kthreadd, kworker, etc.]
MANDATORY PRACTICES
- Never kill processes by pattern without verification - always list first
- Prefer graceful shutdown (SIGTERM) before force kill (SIGKILL)
- Wait for confirmation before killing processes with open files/network connections
- Log all process terminations with reason
- Never modify OOM killer settings on system processes
CONSENSUS REQUIREMENTS
| Operation | Risk Level | Consensus Required |
|---|
| list_processes | low | any |
| get_process_info | low | any |
| monitor_resources | low | any |
| start_process | medium | majority |
| stop_process (graceful) | medium | majority |
| kill_process (force) | high | unanimous |
| manage_service | high | unanimous |
| set_priority | medium | majority |
Capabilities
list_processes
List running processes with optional filtering.
Usage:
ps aux
pstree -p
pgrep -la python
ps -u animus
ps aux --sort=-%cpu | head -20
ps aux --sort=-%mem | head -20
ps aux --width 200
get_process_info
Get detailed information about a specific process.
Usage:
ps -p 1234 -o pid,ppid,user,%cpu,%mem,etime,comm
cat /proc/1234/status
lsof -p 1234
ss -tulpn | grep 1234
pmap 1234
cat /proc/1234/environ | tr '\0' '\n'
ls -la /proc/1234/cwd
ls -la /proc/1234/fd
monitor_resources
Get system resource utilization.
Usage:
vmstat 1 5
mpstat -P ALL 1 3
free -h
cat /proc/meminfo
iostat -x 1 3
sar -n DEV 1 3
echo "=== CPU ===" && top -bn1 | head -5
echo "=== MEMORY ===" && free -h
echo "=== DISK ===" && df -h
echo "=== LOAD ===" && uptime
Python helper for structured output:
import psutil
import json
def get_system_metrics():
return {
"cpu_percent": psutil.cpu_percent(interval=1),
"cpu_per_core": psutil.cpu_percent(interval=1, percpu=True),
"memory": dict(psutil.virtual_memory()._asdict()),
"swap": dict(psutil.swap_memory()._asdict()),
"disk": {p.mountpoint: dict(psutil.disk_usage(p.mountpoint)._asdict())
for p in psutil.disk_partitions()},
"network": dict(psutil.net_io_counters()._asdict()),
"load_average": psutil.getloadavg(),
"boot_time": psutil.boot_time(),
}
print(json.dumps(get_system_metrics(), indent=2))
start_process
Launch a new process.
Usage:
python3 /path/to/script.py
nohup python3 /path/to/script.py > /var/log/animus/script.log 2>&1 &
echo $! > /var/run/animus/script.pid
systemd-run --user --scope \
-p MemoryMax=512M \
-p CPUQuota=50% \
python3 /path/to/script.py
env VAR1=value1 VAR2=value2 python3 /path/to/script.py
cd /path/to/workdir && python3 script.py
setsid python3 /path/to/script.py > /var/log/animus/script.log 2>&1 &
Safety:
- Always capture PID for tracking
- Redirect output to logs
- Set resource limits for untrusted scripts
- Verify executable exists and is permitted
stop_process
Gracefully stop a process (SIGTERM).
Usage:
kill -TERM 1234
timeout 30 tail --pid=1234 -f /dev/null
ps -p 1234 > /dev/null && echo "Still running" || echo "Stopped"
pgrep -la myprocess
pkill -TERM myprocess
kill -TERM $(cat /var/run/animus/myprocess.pid)
rm /var/run/animus/myprocess.pid
Safety:
- Always try SIGTERM first
- Wait reasonable time before escalating
- Check for child processes
- Clean up PID files
kill_process
Force kill a process (SIGKILL).
Usage:
kill -9 1234
sleep 1 && ps -p 1234 > /dev/null && echo "FAILED TO KILL" || echo "Killed"
kill -9 -$(ps -o pgid= -p 1234 | tr -d ' ')
Safety:
- REQUIRES UNANIMOUS CONSENSUS
- Only use after graceful stop fails
- Log reason for force kill
- Check for orphaned child processes
- May cause data loss - warn user
manage_service
Control systemd services.
Usage:
systemctl status myservice
sudo systemctl start myservice
sudo systemctl stop myservice
sudo systemctl restart myservice
sudo systemctl enable myservice
sudo systemctl disable myservice
systemctl is-active myservice
journalctl -u myservice -n 50 --no-pager
systemctl --user status myservice
systemctl --user start myservice
Safety:
- REQUIRES UNANIMOUS CONSENSUS
- Never disable critical services (sshd, systemd, networking)
- Check dependencies before stopping
- Verify service file exists
set_priority
Change process priority (nice/ionice).
Usage:
renice 10 -p 1234
nice -n 15 python3 script.py
ionice -c 3 -p 1234
ionice -c 2 -n 7 python3 script.py
nice -n 10 ionice -c 2 -n 7 python3 script.py
Safety:
- Only increase priority (lower number) with unanimous consensus
- Never set negative nice values without explicit approval
background_job_control
Manage background jobs in current session.
Usage:
jobs -l
bg %1
fg %1
disown %1
Examples
Example 1: Find and stop a runaway process
Intent: "Something is using 100% CPU, find and stop it"
Execution:
ps aux --sort=-%cpu | head -10
ps -p 5678 -o pid,ppid,user,%cpu,%mem,etime,comm,args
lsof -p 5678 | head -20
kill -TERM 5678
for i in {1..30}; do
ps -p 5678 > /dev/null 2>&1 || break
sleep 1
done
ps -p 5678 > /dev/null 2>&1 && echo "Still running - may need force kill" || echo "Successfully stopped"
Example 2: Launch a monitored background task
Intent: "Run the data sync script in background with resource limits"
Execution:
mkdir -p /var/log/animus
systemd-run --user --scope \
--unit=animus-datasync \
-p MemoryMax=1G \
-p CPUQuota=50% \
bash -c 'python3 /home/gorgon/scripts/datasync.py >> /var/log/animus/datasync.log 2>&1'
systemctl --user show animus-datasync --property=MainPID
systemctl --user show animus-datasync --property=MainPID --value > /var/run/animus/datasync.pid
systemctl --user status animus-datasync
Example 3: System health check for Gorgon metrics
Intent: "Get current system metrics for supervisor decision making"
Execution:
python3 << 'EOF'
import psutil
import json
from datetime import datetime
metrics = {
"timestamp": datetime.now().isoformat(),
"cpu": {
"percent": psutil.cpu_percent(interval=1),
"count": psutil.cpu_count(),
"count_physical": psutil.cpu_count(logical=False),
"load_avg": psutil.getloadavg()
},
"memory": {
"total_gb": round(psutil.virtual_memory().total / (1024**3), 2),
"available_gb": round(psutil.virtual_memory().available / (1024**3), 2),
"percent": psutil.virtual_memory().percent
},
"disk": {
"total_gb": round(psutil.disk_usage('/').total / (1024**3), 2),
"free_gb": round(psutil.disk_usage('/').free / (1024**3), 2),
"percent": psutil.disk_usage('/').percent
},
"processes": {
"total": len(psutil.pids()),
"running": len([p for p in psutil.process_iter(['status']) if p.info['status'] == 'running'])
}
}
print(json.dumps(metrics, indent=2))
EOF
Integration with Gorgon Supervisor
The process_management skill provides critical data for the Triumvirate's resource governance:
def collect_metrics_for_triumvirate():
"""Collect metrics for supervisor decision making."""
metrics = execute_skill("process_management", "monitor_resources")
triumvirate.evaluate_resources(metrics)
Error Handling
| Error | Response |
|---|
| Process not found | Report, verify PID was correct |
| Permission denied | Report, check if sudo required |
| Process is protected | Refuse operation, explain why |
| Kill failed | Report, may be zombie - check parent |
| Service not found | List available services, suggest alternatives |
Output Format
{
"success": true,
"operation": "stop_process",
"pid": 1234,
"details": {
"signal": "SIGTERM",
"wait_time_seconds": 3.2,
"clean_shutdown": true
},
"timestamp": "2026-01-27T10:30:00Z"
}