我正在尝试设置每个用户的进程限制,其中大多数都是使用 sudo --user 运行的。为什么我的系统上的 user-1001 和 user-1008 有切片文件,但我无法在 1009 上获取它?
# systemctl set-property user-1009.slice CPUQuota=50%
Failed to set unit properties on user-1009.slice: Unit user-1009.slice is not loaded.
# systemctl status user-1009.slice
● user-1009.slice
Loaded: loaded
Active: inactive (dead)
我尝试手动创建文件
# touch /etc/systemd/system/user-1009.slice
# systemctl status user-1009.slice
● user-1009.slice
Loaded: masked (/etc/systemd/system/user-1009.slice; masked; vendor preset: disabled)
Active: inactive (dead)
# systemctl set-property user-1009.slice CPUQuota=50%
Failed to set unit properties on user-1009.slice: Unit user-1009.slice is not loaded.
这对我来说也没有意义,测试进程(PID 26668)显示在 ps -U 1009 中,但它在用户 1008 的切片下运行(因为用户 1008 使用 sudo 来运行它?)
# ps -U 1009 ; systemctl status user-1008.slice
PID TTY TIME CMD
15727 pts/1 00:00:00 bash
26668 ? 00:00:00 testprocess
● user-1008.slice - User Slice of testuser
Loaded: loaded (/run/systemd/system/user-1008.slice; static; vendor preset: disabled)
Drop-In: /run/systemd/system/user-1008.slice.d
└─50-After-systemd-logind\x2eservice.conf, 50-After-systemd-user-sessions\x2eservice.conf, 50-Description.conf, 50-TasksMax.conf
Active: active since Thu 2018-08-30 19:35:01 EDT; 2 days ago
CGroup: /user.slice/user-1008.slice
└─session-1801668.scope
└─26668 ./testprocess
四处搜索后,我发现人们都说要以用户身份登录才能解决这个问题,但显然该用户已经打开了进程。我尝试在另一个终端中使用 su - user1009,但似乎没有帮助
答案1
万一其他人需要解决方案,除了使用 sudo 之外,sudo systemd-run 对我来说也很有用
$ sudo systemd-run --uid=1009 --slice=user-1009 sleep 10
# ps -U 1009 ; systemctl status user-1009.slice
PID TTY TIME CMD
20199 ? 00:00:00 sleep
● user-1009.slice
Loaded: loaded
Active: active since Sun 2018-09-02 01:46:57 EDT; 2s ago
CGroup: /user.slice/user-1009.slice
└─run-20198.service
└─20199 /bin/sleep 10