Add forgotten run-with-cgroup.sh script
This commit is contained in:
parent
640cd5746b
commit
8e9343b632
1 changed files with 19 additions and 0 deletions
19
common/run-in-cgroup.sh
Executable file
19
common/run-in-cgroup.sh
Executable file
|
@ -0,0 +1,19 @@
|
||||||
|
#!/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
|
Reference in a new issue