process-management
Production-grade process management - jobs, signals, cron, systemd
What this skill does
# Process Management Skill
> Master process control, signals, scheduling, and monitoring
## Learning Objectives
After completing this skill, you will be able to:
- [ ] List and inspect running processes
- [ ] Send and handle signals properly
- [ ] Run background jobs and daemons
- [ ] Schedule tasks with cron and systemd
- [ ] Monitor system resources
## Prerequisites
- Bash basics
- Linux system fundamentals
- User permissions understanding
## Core Concepts
### 1. Process Inspection
```bash
# List processes
ps aux # All processes
ps -ef # Full format
ps --forest # Tree view
# Find processes
pgrep -f "pattern" # PID by pattern
pidof nginx # PID by name
ps aux | grep '[n]ginx' # Grep trick
# Resource usage
top # Real-time view
htop # Better interface
```
### 2. Signal Handling
```bash
# Send signals
kill PID # SIGTERM (15)
kill -9 PID # SIGKILL (9)
kill -HUP PID # SIGHUP (1)
killall nginx # By name
pkill -f "pattern" # By pattern
# Handle signals in scripts
trap 'cleanup' EXIT
trap 'echo "Interrupted"' INT
cleanup() {
rm -f "$TEMP_FILE"
exit 0
}
```
### 3. Background Jobs
```bash
# Background execution
command & # Run in background
nohup command & # Immune to hangup
nohup cmd > log.txt 2>&1 & # With logging
# Job control
jobs # List jobs
fg %1 # Foreground job 1
bg %1 # Background job 1
disown # Detach from shell
```
### 4. Cron Scheduling
```bash
# Cron format
# ┌─── minute (0-59)
# │ ┌─── hour (0-23)
# │ │ ┌─── day of month (1-31)
# │ │ │ ┌─── month (1-12)
# │ │ │ │ ┌─── day of week (0-6)
# * * * * * command
# Examples
0 * * * * # Every hour
*/15 * * * * # Every 15 minutes
0 0 * * * # Daily at midnight
0 0 * * 0 # Weekly on Sunday
# Edit crontab
crontab -e
crontab -l
```
## Common Patterns
### Daemon Pattern
```bash
start_daemon() {
nohup ./daemon.sh >> /var/log/daemon.log 2>&1 &
echo "$!" > /var/run/daemon.pid
disown
}
stop_daemon() {
if [[ -f /var/run/daemon.pid ]]; then
kill "$(cat /var/run/daemon.pid)"
rm /var/run/daemon.pid
fi
}
```
### Cron with Locking
```bash
# Prevent overlapping runs
0 * * * * /usr/bin/flock -n /var/lock/job.lock /path/to/script.sh
```
### Signal Handler
```bash
#!/usr/bin/env bash
set -euo pipefail
cleanup() {
echo "Cleaning up..."
rm -f "$TEMP_FILE"
}
trap cleanup EXIT INT TERM
# Main logic
TEMP_FILE=$(mktemp)
# ... work with temp file
```
## Signal Reference
| Signal | Number | Default | Common Use |
|--------|--------|---------|------------|
| SIGHUP | 1 | Terminate | Reload config |
| SIGINT | 2 | Terminate | Ctrl+C |
| SIGQUIT | 3 | Core dump | Ctrl+\ |
| SIGKILL | 9 | Terminate | Force kill |
| SIGTERM | 15 | Terminate | Graceful stop |
| SIGSTOP | 19 | Stop | Pause |
| SIGCONT | 18 | Continue | Resume |
## Anti-Patterns
| Don't | Do | Why |
|-------|-----|-----|
| `kill -9` first | `kill -TERM` first | Allow cleanup |
| Kill PID 1 | Never | Crashes system |
| Cron without logs | Log all output | Debug issues |
## Practice Exercises
1. **Process Monitor**: Script to monitor a process
2. **Daemon Script**: Create a proper daemon
3. **Cron Job**: Schedule a backup job
4. **Signal Handler**: Graceful shutdown script
## Troubleshooting
### Common Errors
| Error | Cause | Fix |
|-------|-------|-----|
| `No such process` | Already dead | Check with ps |
| `Operation not permitted` | Wrong owner | Use sudo |
| Cron not running | PATH issues | Use full paths |
### Debug Techniques
```bash
# Check if process exists
ps -p $PID
# Debug cron
grep CRON /var/log/syslog
# Trace process
strace -p $PID
```
## Resources
- [GNU Coreutils - Process](https://www.gnu.org/software/coreutils/manual/)
- [Crontab Guru](https://crontab.guru/)
- [systemd Timers](https://www.freedesktop.org/software/systemd/man/systemd.timer.html)
Related in General
modeling-omnistudio-epc-catalog
IncludedSalesforce Industries CME EPC product-modeling skill for Product2-based catalog creation. Use when creating EPC products, configuring product attributes, building offer bundles with Product Child Items, or reviewing EPC DataPack JSON metadata for product catalog changes. TRIGGER when: user creates or updates Product2 EPC records, AttributeAssignment payloads, AttributeMetadata/AttributeDefaultValues, Offer bundles, or ProductChildItem relationships. DO NOT TRIGGER when: designing OmniScripts/FlexCards/Integration Procedures (use building-omnistudio-omniscript, building-omnistudio-flexcard, or building-omnistudio-integration-procedure), implementing Apex business logic (use generating-apex), or troubleshooting deployment pipelines (use deploying-metadata).
relationship-science-coach
IncludedUse this skill for direct, practical adult relationship coaching: couples conflict, repair, trust, marriage, dating, flirting, attachment patterns, emotional connection, sex, desire differences, eroticism, kink negotiation, affection, love languages, breakups, and long-term passion. Draw on Gottman, EFT and Hold Me Tight, attachment science, modern sex research, Perel, Nagoski, Kerner, Schnarch, Love and Stosny, and flexible love-language tools. Be concrete and low-hedge. Redirect only for imminent danger, abuse, coercive control, minors, non-consent, self-harm, stalking, or medical/legal/psychiatric decisions.
building-sf-integrations
IncludedSalesforce integration architecture and runtime plumbing with 120-point scoring. Use this skill to set up Named Credentials, External Credentials, External Services, REST/SOAP callout patterns, Platform Events, and Change Data Capture. TRIGGER when: user sets up Named Credentials, External Services, REST/SOAP callouts, Platform Events, CDC, or touches .namedCredential-meta.xml files. DO NOT TRIGGER when: Connected App/OAuth config (use configuring-connected-apps), Apex-only logic (use generating-apex), or data import/export (use handling-sf-data).
venue-templates
IncludedAccess comprehensive LaTeX templates, formatting requirements, and submission guidelines for major scientific publication venues (Nature, Science, PLOS, IEEE, ACM), academic conferences (NeurIPS, ICML, CVPR, CHI), research posters, and grant proposals (NSF, NIH, DOE, DARPA). This skill should be used when preparing manuscripts for journal submission, conference papers, research posters, or grant proposals and need venue-specific formatting requirements and templates.
let-fate-decide
IncludedDraws the 12 Houses of the Zodiac Tarot spread to inject entropy into planning when prompts are vague, ambiguous, or casually delegated. Interprets the spread to guide next steps. Use when the user says 'let fate decide', 'YOLO', 'whatever', 'idk', or other nonchalant phrases, makes Yu-Gi-Oh references, or when you are about to arbitrarily pick between multiple reasonable approaches. Prefer over ask-questions-if-underspecified when the user's tone is casual or playful rather than precision-seeking.
net-ops
IncludedCross-platform network troubleshooting (Windows, macOS, Linux) via local or remote shell. Use for: DNS broken, can't resolve hostnames, nslookup/dig works but apps fail, NRPT, WFP, scutil, /etc/resolver, systemd-resolved, /etc/resolv.conf, NetworkManager, VPN DNS leak residue (ProtonVPN/Mullvad/WireGuard/AnyConnect), AV/firewall blocking DNS or DoH, Tailscale DNS interaction, intermittent connectivity, remote diagnostics over SSH.