Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Could someone tell me how to set the default value of nice (as displayed by top) of a user? I have found that /etc/security/limits.conf is the place but if I put either:

username_of_a_guy  -  nice  19
username_of_a_guy  soft  nice  19
username_of_a_guy  hard  nice  19

It doesn't work (while it should, right?).

Note that I've rebooted since then.

Thank you very much in advance for any help. I'm using debian unstable (uptodate).

Context:

At my work, we have a local network: everyone has its own computer and everyone can create an account on someone else's machine if one likes. The rule of thumb is simply that if you work on someone else computer, please nice your processes (nice 19).

I would like to set the default nice value for a given user to 19 once and for all (he pretends he forgets all the time to nice).

share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

I believe the correct format is:

@users      -       priority        10
username    -       priority        19

This is an example of the settings I am using in production (obviously with real users/groups).

The nice setting is to determine the maximum nice value someone can set their process to, not their default priority.

share|improve this answer
    
First of all, thanks for your answer ( thank you as well, @mattdm ). It seems this method works. However, I'm still confused about the difference between "nice" and "priority" : both are displayed by "top" but the value quoted for nice is the one I have to set for priority. It looks a bit strange to me. Also, does a bigger priority (say 39 instead of 20) mean a less important process as it does for nice? Thank you. –  Alex Mar 10 '11 at 14:10
1  
The 'NI' nice priority in top is what would be set by the limits priority setting. This will be the default priority of any processes for that user/group when they log in. You can only set this to be between -20 and 20. The 'PR' value in top is the actual scheduler priority, which is determined by several factors by the kernel's scheduler. –  jsbillings Mar 10 '11 at 14:26
    
Also, yes, a higher priority means that it is less likely to be scheduled to get CPU cycles. –  jsbillings Mar 10 '11 at 14:32
    
Ok, thanks a lot for this disambiguation. BTW, I haven't tried the other methods (involving and or cgroup) which might be better in other situations than mine (need of a continuous check, or management of many users -which is a bit too much in my case). –  Alex Mar 10 '11 at 16:05
add comment

I can confirm that that doesn't work on my system either. The docs say "kernel 2.6.11 and up", and I'm on Fedora rawhide with kernel 2.6.38-rc6. I wonder if it is scheduler-dependent, and doesn't work with the introduced-in-2.6.23 CFQ ("Completely Fair Scheduler").

Something that will work, though, is the impossible-to-search-for-because-of-its-horrible-name and — the auto-nice daemon. See http://and.sourceforge.net/. This is available from Fedora with yum install and, but unfortunately doesn't seem to be in EPEL. And it's in Debian too: apt-get install and.

If you are using a modern distribution, though, there's an Even Better Way. You can use the tools from libcgroup to set up a kernel-level cgroup limiting CPU shares, and to automatically "classify" that user's processes into this cgroup. With this, you can also prioritize I/O, and limit memory usage (including share of the disk cache).

share|improve this answer
    
I agree that using cgroups is an excellent way to limit other people from hogging all the CPU cycles on your computer. Sadly, the systems I support (RHEL5) don't have kernels that support it, so I have to stick with adjusting the priority. Once we update to RHEL6, I'm sure we'll have some fairly complex cgroups settings. –  jsbillings Mar 10 '11 at 15:00
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.