Last active
October 12, 2023 14:13
-
-
Save ananace/044c82425f4f1ac561506be9ad15d486 to your computer and use it in GitHub Desktop.
Small script to launch a process in a slice/cgroup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -euo pipefail | |
# Drop in /usr/local/bin/run-in-slice | |
# | |
# Requires system to be running systemd and cgroupsv2 | |
SLICE="$1" | |
shift | |
[[ "$SLICE" = *".slice" ]] || SLICE="${SLICE}.slice" | |
SLICE_DIR="/sys/fs/cgroup/user.slice/user-$UID.slice/user@$UID.service/$SLICE" | |
mkdir -p "$SLICE_DIR" | |
echo "Moving to $SLICE_DIR" | |
echo $$ > "$SLICE_DIR/cgroup.procs" | |
exec $@ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment