[Linux]限制组或用户的CPU使用

时间:2014-07-07 08:37:23

标签: linux cpu

我需要按组或用户限制cpu使用 有任何软件都可以做到这一点 1.我有学习cpulimit,但cpulimit不能按组或用户,cpulimit只能通过进程或进程id 2.我有学习/etc/security/limits.conf,但只限制cpu时间,而不是cpu使用

2 个答案:

答案 0 :(得分:0)

您可以使用ulimit -a来检查为特定用户分配的限制,以便您可以尝试cpu限制

ulimit -t

您可以通过

设置cpu限制
ulimit -t 100 

ulimit使用了getrlimit()和setrlimit()的手册页

   RLIMIT_CPU
          CPU time limit in seconds.  When the process reaches the soft limit, it is sent a SIGXCPU signal.  The default action for this  sig‐
          nal is to terminate the process.  However, the signal can be caught, and the handler can return control to the main program.  If the
          process continues to consume CPU time, it will be sent SIGXCPU once per second until the hard limit is reached, at which time it  is
          sent SIGKILL.  (This latter point describes Linux behavior.  Implementations vary in how they treat processes which continue to con‐
          sume CPU time after reaching the soft limit.  Portable applications that need to catch this signal should perform an orderly  termi‐
          nation upon first receipt of SIGXCPU.)

注意:cpu时间值以秒为单位。

答案 1 :(得分:0)

为此您可以使用linux cgroup,有关您阅读的更多信息,请参阅linux内核Docs Documentation / cgroups / cgroups.txt