| name | signals-monitoring |
| description | This skill should be used when working with Unix process signals, shell trap handlers, macOS unified logging, file watching, process monitoring, and terminal notifications. Use when users ask to "check system logs", "debug my app", "fix script cleanup on Ctrl+C", "add signal handling to a script", "configure log streaming", "build a file watcher", "send a notification from the terminal", or "open a log stream in tmux". |
| metadata | {"version":"1.0.0"} |
Signals & Monitoring
Overview
Two closely paired terminal primitives: signals (sending and handling Unix process signals in shell scripts) and monitoring (observing system state via macOS unified logging, file watching, and process inspection). Completes the loop with notifications — alert yourself when something happens.
When to Use This Skill
- Checking macOS system logs (
log show, log stream)
- Diagnosing why an app is misbehaving or crashing
- Real-time log streaming in a tmux pane (
logwatch)
- Writing structured log entries from shell scripts (
logger)
- Handling Ctrl+C, SIGTERM, SIGHUP in zsh scripts with
trap
- Graceful shutdown patterns for long-running shell functions
- Sending a signal to reload a process config (SIGHUP)
- Watching files for changes and triggering actions (
fswatch, entr)
- Inspecting process resource usage or open file descriptors
- Sending macOS notifications from the terminal (
osascript, terminal-notifier)
- Notifying yourself when a long command finishes
Core Capabilities
1. macOS System Logging
Read, stream, and write to macOS's unified logging system. See references/macos_logging_guide.md for the full reference.
Common operations:
sudo log show --last 1h --predicate 'subsystem=="com.apple.sharing"'
sudo log stream --predicate 'process=="Safari" and type=error'
sudo log stream --predicate 's=com.apple.networking and type=error|fault'
logger -t "my-script" -p user.info "task started"
log show --last 1h --predicate 'process=="logger" and eventMessage contains "my-script"'
When to use: Diagnosing macOS app or system behavior, instrumenting shell scripts, post-mortem investigation of crashes or unexpected behavior.
2. Unix Signals
Send, catch, and handle process signals in shell scripts. See references/signals_guide.md for the full reference.
Common operations:
kill -TERM <pid>
kill -HUP $(pgrep nginx)
kill -9 <pid>
pkill -f "process name pattern"
trap for script cleanup:
trap 'rm -f /tmp/my-lockfile' EXIT
trap 'echo "interrupted, cleaning up..."; cleanup_fn; exit 1' INT TERM
trap 'source ~/.zshrc' HUP
When to use: Scripts that create temp files, hold locks, or run background processes — always add an EXIT trap. Long-running functions that should handle Ctrl+C gracefully.
3. File Watching
Run commands automatically when files change. See references/file_watching_guide.md for the full reference.
fswatch -o ./src | xargs -n1 -I{} make build
ls src/**/*.swift | entr -c swift test
fswatch ~/important-file | xargs -n1 -I{} terminal-notifier -message "File changed"
When to use: Development workflows where you want automatic rebuild/test on save, or monitoring a config file for changes.
4. Notifications
Send macOS notifications from the terminal. See references/notifications_guide.md for the full reference.
osascript -e 'display notification "Build done" with title "Terminal" sound name "Glass"'
terminal-notifier -title "Deploy" -message "Production live" -sound default
notify_when_done pattern — wrap any command and alert on completion:
notify_when_done() {
"$@"
local status=$?
if (( status == 0 )); then
osascript -e "display notification \"$*\" with title \"Done ✓\" sound name \"Glass\""
else
osascript -e "display notification \"$* (exit $status)\" with title \"Failed ✗\" sound name \"Basso\""
fi
return $status
}
When to use: Long-running commands (builds, deploys, test suites) where you want to be alerted when done so you can context-switch away.
logwatch — tmux Log Stream Pane
Open a tmux split pane with a filtered real-time log stream. Useful while developing: keep a log stream open alongside your editor or test runner.
bash /path/to/zsh-dev/scripts/install_autoload.sh logwatch
logwatch com.apple.sharing
logwatch "" "process==\"Safari\""
logwatch
The script is at scripts/logwatch. When inside tmux, it opens a new split pane; otherwise streams in the current terminal.
Diagnostic Workflow
| Symptom | Domain | Reference |
|---|
| App misbehaving, crash investigation | macOS Logging | references/macos_logging_guide.md |
| Script not handling Ctrl+C, leaving temp files | Signals / trap | references/signals_guide.md |
| Want to rebuild/test automatically on file save | File Watching | references/file_watching_guide.md |
| Alert when long command finishes | Notifications | references/notifications_guide.md |
| Need to kill or pause a process | Signals | references/signals_guide.md |
Common Use Cases
"Why is [app] doing this?"
- Stream its logs:
sudo log stream --predicate 'process=="AppName"' --level debug
- Narrow with predicate: add
and type=error to focus on errors
- Check recent history:
sudo log show --last 30m --predicate 'process=="AppName"'
- Refer to
references/macos_logging_guide.md for predicate syntax
"My script leaves temp files when I Ctrl+C"
- Add
trap 'rm -f "$tmpfile"' EXIT at the top of your script
- EXIT fires on Ctrl+C (SIGINT), SIGTERM, and normal exit
- Refer to
references/signals_guide.md for trap patterns
"I want tests to run automatically when I save"
brew install entr
ls src/**/*.swift | entr -c swift test
- Or with fswatch:
fswatch -o ./src | xargs -n1 -I{} make test
- Refer to
references/file_watching_guide.md
"Notify me when my deploy finishes"
- Use
notify_when_done kubectl apply -f k8s/
- Or append:
make deploy && osascript -e 'display notification "Deploy done" with title "CI"'
- Refer to
references/notifications_guide.md
Resources
scripts/
logwatch — zsh autoload function: open tmux pane with filtered log stream
references/
macos_logging_guide.md — macOS unified log command, predicate filtering, writing logs from shell
signals_guide.md — Unix signal table, kill/pkill, trap patterns for shell scripts
file_watching_guide.md — fswatch, entr, process inspection (pgrep, lsof)
notifications_guide.md — osascript notifications, terminal-notifier, notify_when_done pattern
Advanced / Future Capabilities
The following tools exist for deep system tracing and are known to this skill, but not yet covered in v1 guidance. Ask about them and expect a pointer to documentation rather than step-by-step help:
dtrace / dtruss — DTrace-based system call tracing (requires SIP disabled on modern macOS)
instruments CLI — Apple's profiling and tracing tool (xcrun xctrace)
ktrace / kdebug — kernel-level event tracing