2

I have an SSH server where users login to do various tasks. The problem is I have 4 cores, and one user is running tasks on 4. How can I limit the number of cores any given user can use?

This is not a virtual machine.

UPDATE: I was reading /etc/security/limits.conf and saw

#*               soft    core            0
#root            hard    core            100000
#*               hard    rss             10000
#@student        hard    nproc           20
#@faculty        soft    nproc           20
#@faculty        hard    nproc           50
#ftp             hard    nproc           0
#ftp             -       chroot          /ftp
#@student        -       maxlogins       4

I tried setting this up so that a user is limited to 3 processes. but the user gets

 -bash: fork: retry: No child processes

in their terminal.

I have started looking into ulimit, and quota

j0h
  • 15,365

2 Answers2

1

taskset(1) may help you. It can set the core number for one process. You can use ps(1) to get all the process of target user. For example,

housezet@arch: ~
$ ps aux | awk '/^housezet/{print $2}' | xargs -l taskset -p 0x00000001

This wil limit housezet's current process only use one core. And if limiting cpu usage is also acceptable, you can also consider using cpulimit(1).

Avinash Raj
  • 80,446
House Zet
  • 449
0

I don't believe there is any existing tool that would handle what you're after, as it's not a particularly easy thing to do. Handling of which process goes where isn't done in userspace.

The only way I can think of to kind of do what you're after is to use ulimit to set the maximum amount of CPU time, which would prevent a user from hogging everything too much. You can also change a user's nice level, so if a particular user is slamming the CPU you can lower their prority.

ruscur
  • 1,053