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
  • 14,825

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
  • 78,556
House Zet
  • 457
  • 3
  • 8
  • I am going back and forth with this solution. How would I set this to run when the user logs in? – j0h Feb 10 '14 at 00:58
  • 1
    @j0h For systemwide, create a service under /etc/systemd/system/multi-user.target.wants/ or startup script under /etc/init.d/ with something like watch(1) to repeat this command. Putting script under /etc/profile.d/ will make it works when user logs in. You can look at here for more about autostarting. – House Zet Feb 10 '14 at 01:15
  • If a have 8 cores and do this for 2 users limiting to 4 cores each. would it mean that when they run the desktop (mate ) and chrome in mate, that chrome could use between 1 and 4 cores per user? That's what I want to do. They would log in via vnc. – ycomp Jul 10 '17 at 19:54
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,043
  • 1
  • 7
  • 11