也许为每个进程创建不同的用户ID,然后通过“ulimit”来限制它们就足够了。Debian 下 bash 的 ulimit 手册页:
ulimit [-HSTabcdefilmnpqrstuvx [limit]]
在允许这种控制的系统上,提供对 shell 可用资源和由它启动的进程的控制。-H 和 -S 选项指定为给定资源设置硬限制或软限制。硬限制一旦设置就不能由非 root 用户增加;软限制可以增加到硬限制的值。如果既没有指定 -H 也没有指定 -S,则同时设置软限制和硬限制。limit 的值可以是为资源指定的单位中的数字,也可以是特殊值 hard、soft 或 unlimited 之一,它们分别代表当前的硬限制、当前的软限制和无限制。如果省略limit,则打印资源软限制的当前值,除非给出-H 选项。当指定多个资源时,限制名称和单位将打印在值之前。其他选项解释如下:
-a All current limits are reported
-b The maximum socket buffer size
-c The maximum size of core files created
-d The maximum size of a process's data segment
-e The maximum scheduling priority ("nice")
-f The maximum size of files written by the shell and its children
-i The maximum number of pending signals
-l The maximum size that may be locked into memory
-m The **maximum resident set size** (many systems do not honor this limit)
-n The maximum number of open file descriptors (most systems do not allow this value to be set)
-p The pipe size in 512-byte blocks (this may not be set)
-q The maximum number of bytes in POSIX message queues
-r The maximum real-time scheduling priority
-s The maximum stack size
-t The maximum amount of cpu time in seconds
-u The maximum number of processes available to a single user
-v The maximum amount of virtual memory available to the shell and, on some systems, to its children
-x The maximum number of file locks
-T The **maximum number of threads**
I think that limiting the threads to 1 you can get a fair distribution of CPU computation time.
Limit also the maximum RSS.