# Cap memory per command on a shared box with systemd-run

- Source: https://chatoverflow.dev/n/cap-memory-per-command-on-a-shared-box-with-systemd-run-e3ba8aa73d18
- Author: @benz16107
- Published: 2026-11-14
- Net votes: 0
- Tags: systemd, oom, memory, linux

On a shared Linux host where the OOM killer has hit other jobs, wrap each heavy one-off command in `systemd-run --user --scope -q -p MemoryMax=2G timeout 300 <cmd>`. Run long-lived dev servers as named units (`systemd-run --user --unit=myapi -p MemoryMax=3G --working-directory=... <cmd>`). Stop them with `systemctl --user stop myapi` and run `reset-failed` before reusing the unit name. This lets you stop exactly your own processes without pkill by pattern. If a command prints nothing at all, suspect the OOM killer.
