我想限制cgroup
由 创建的临时命令的资源消耗systemd-run
,类似于cgcreate
相反的做法,但我不确定这是否有意义?
我想确保我的尝试正确,谢谢大家!
┌──[[email protected]]-[~]
└─$ systemd-run -p MemoryLimit=5M -p CPUShares=100 --unit=sleep-50 --slice=test sleep 50
Running as unit sleep-50.service.
┌──[[email protected]]-[~]
└─$ systemctl status sleep-50.service
● sleep-50.service - /usr/bin/sleep 50
Loaded: loaded (/run/systemd/system/sleep-50.service; static; vendor preset: disabled)
Drop-In: /run/systemd/system/sleep-50.service.d
└─50-CPUShares.conf, 50-Description.conf, 50-ExecStart.conf, 50-MemoryLimit.conf, 50-Slice.conf
Active: active (running) since 六 2022-10-29 01:29:29 CST; 10s ago
Main PID: 33234 (sleep)
Memory: 92.0K (limit: 5.0M)
CGroup: /test.slice/sleep-50.service
└─33234 /usr/bin/sleep 50
10月 29 01:29:29 liruilongs.github.io systemd[1]: Started /usr/bin/sleep 50.
┌──[[email protected]]-[~]
└─$ systemctl cat sleep-50.service
# /run/systemd/system/sleep-50.service
# Transient stub
# /run/systemd/system/sleep-50.service.d/50-CPUShares.conf
[Service]
CPUShares=100
# /run/systemd/system/sleep-50.service.d/50-Description.conf
[Unit]
Description=/usr/bin/sleep 50
# /run/systemd/system/sleep-50.service.d/50-ExecStart.conf
[Service]
ExecStart=
ExecStart=@/usr/bin/sleep "/usr/bin/sleep" "50"
# /run/systemd/system/sleep-50.service.d/50-MemoryLimit.conf
[Service]
MemoryLimit=5242880
# /run/systemd/system/sleep-50.service.d/50-Slice.conf
[Service]
Slice=test.slice
┌──[[email protected]]-[~]
└─$ systemctl status sleep-50.service
Unit sleep-50.service could not be found.
┌──[[email protected]]-[~]
└─$