systemd-run(1)
Run a program in a new systemd unit, useful for setting resource limits, cgroups, and tracking processes.
Synopsis
systemd-run [OPTIONS] [COMMAND] [ARGUMENTS...]Description
systemd-run launches a program in a transient systemd unit, which allows you to apply systemd settings like resource limits, CPU/memory constraints, and service properties to arbitrary commands. This is useful for temporary one-off processes that need special isolation or accounting.
The unit is automatically cleaned up when the process exits. You can run programs in the system instance or user instance, as a service, scope, or timer unit.
Common options
| Flag | What it does |
|---|---|
-u, --unit=NAME | Set the name of the transient unit (default: auto-generated) |
-p, --property=NAME=VALUE | Set systemd unit properties like MemoryLimit=100M, CPUQuota=50% |
--scope | Create a scope unit instead of a service (default is service) |
--user | Run in the user instance instead of the system instance |
-d, --working-directory=PATH | Set working directory for the process |
-E, --setenv=NAME=VALUE | Set environment variables for the process |
--no-wait | Start the unit asynchronously and return immediately |
-S, --slice=SLICE | Place unit in the specified slice (e.g., user-background.slice) |
--pty | Allocate a pseudo-terminal for the process |
-q, --quiet | Suppress status output |
Examples
Run htop in a user scope unit, easy to track and kill the process tree
systemd-run --user --scope htopRun myapp with 100MB memory limit and 50% CPU quota
systemd-run -p MemoryLimit=100M -p CPUQuota=50% myapp --optionRun script.sh with working directory /tmp and custom environment variable
systemd-run -d /tmp --setenv=VAR=value ./script.shStart an async user backup job and return immediately without waiting
systemd-run --user --no-wait -u backup-job /usr/local/bin/backup.shRun Python script in a named unit with memory accounting enabled
systemd-run -u heavy-task -p MemoryAccounting=yes python3 analysis.pyStart an interactive bash shell in a user instance with terminal
systemd-run --pty --user bashRun wget in the background.slice for lower priority execution
systemd-run -S background.slice wget https://example.com/file.tar.gz