Skip to main content
Run shell commands in the background and return immediately. This is ideal for long-running commands that you want to monitor and manage separately.

Overview

Background command execution is perfect for:
  • Long-running commands (>5 minutes)
  • Server processes that need to keep running
  • Commands that don’t need immediate results
  • Parallel execution of multiple commands
Background commands return immediately with a process_id. Use process management to check status and manage background processes.

Starting Background Commands

Start a command in the background:

Checking Process Status

Check the status of background commands:

Long-Running Servers

Start long-running server processes:

Environment Variables

Pass environment variables to background commands:

Timeout Configuration

Set timeout for background commands:

Complete Example

Here’s a complete example showing background command workflow:

Best Practices

1

1. Extract Process IDs

Extract process IDs from the result to track and manage background commands.
2

2. Set Appropriate Timeouts

Set timeouts based on expected execution time. Default is 30 seconds, but increase for longer tasks.
3

3. Monitor Status Regularly

Check process status periodically to track progress and detect failures early.
4

4. Use Process Management

Use list_processes() and kill_process() to monitor and control background commands.
5

5. Handle Failures

Check for failed status and access stderr for error details when commands fail.

Next Steps