This repository has been archived on 2024-10-17. You can view files and clone it, but cannot push or open issues or pull requests.
MahiroOS-jhalfs/common/run-in-cgroup.sh

20 lines
529 B
Bash
Raw Normal View History

#!/bin/bash
if [ -z "$CPUSPEC" ] || [ "$#" -lt 1 ]; then
echo "usage: CPUSPEC=... $0 command"
exit 1
fi
set +e
if type systemd-run >/dev/null 2>&1 ; then
sudo systemd-run -G --pty -d --uid=$(whoami) -p AllowedCPUs="$CPUSPEC" "$@"
else
sudo mkdir /sys/fs/cgroup/jhalfs
sudo sh -c "echo +cpuset > /sys/fs/cgroup/cgroup.subtree_control"
sudo sh -c "echo \"$CPUSPEC\" > /sys/fs/cgroup/jhalfs/cpuset.cpus"
(sudo sh -c "echo $BASHPID > /sys/fs/cgroup/jhalfs/cgroup.procs" &&
exec "$@")
sudo rmdir /sys/fs/cgroup/jhalfs
fi