Background Process Best Practices
<housekeeping>Keep the Process List Clean
- •Kill processes when done - don't leave stale servers running
- •Use
background_process_cleanupperiodically to remove exited processes - •Before launching, check
background_process_listto avoid duplicates - •Use
remove: truewhen killing to clean up in one step
Verify Startup
After launching, wait before reading output - servers need time to start:
- •Launch the process
- •Sleep at least 30 seconds (use bash
sleepor just wait before next action) - •
background_process_readto confirm startup - •If output is empty or incomplete, wait longer and re-read
Look for: "listening on", "ready", "started" - or errors like port conflicts
Use Meaningful IDs
When running multiple processes, set custom id for clarity:
- •
id: "frontend"andid: "backend"instead ofvite-1,node-2 - •Makes kill/read commands unambiguous
When to Use Each Signal
| Signal | Use When |
|---|---|
| SIGTERM (default) | Normal shutdown - gives process time to cleanup |
| SIGINT | Simulate Ctrl+C - some processes handle this differently |
| SIGKILL | Process won't die with SIGTERM - force kill |
- •Processes persist for the session - they don't auto-cleanup on conversation end
- •Output buffer is limited (500 lines default) - increase
maxOutputLinesfor verbose builds - •stderr is prefixed with
[stderr]in output - helps distinguish errors