Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a high priority service that I start with sudo nice -n -10 process. This process does not need superuser rights though, except for the priority elevation. But nice requires superuser privileges to elevate priority.

How do I run a process with elevated priority, without also running it as root?

share|improve this question

3 Answers 3

up vote 2 down vote accepted

Check out /etc/security/limits.conf. There you can specify which priorities that users or groups are allowed to use. Manual page: man 5 limits.conf

share|improve this answer
    
Thank you kindly. I can set the minimum priority for the user to -10, and skip using sudo completely. –  Myrddin Emrys Jan 21 '11 at 18:25

One possibility is this (which I just thought of after asking):

sudo nice -10 sudo -u user command

But it seems like there should be a more elegant method.

share|improve this answer

The other possibility is using sudo renice to change the process's priority after starting it. To obtain the process's PID, you can use ps and sed, or you can start it in background and get its process directly from the shell:

process &
pid=$!
sudo renice -10 $pid
fg $pid                 # if you don't want it in background

Note that if the process spawns other processes and exits, it'll probably have done so by the time renice runs, so you'll want to use ps to get the PID of the child process/processes instead, and renice those.

share|improve this answer
    
This would work, but I think it's even more awkward than the answer I gave (sudo nice -10 sudo -u user command) –  Myrddin Emrys Jan 21 '11 at 18:26
    
However this answer doesn't mess with the environment like sudo does. For instance, sudo will reset LD_LIBRARY_PATH even with -E. –  Trevor Robinson Aug 20 '13 at 19:38
    
Also note that fg can only be used directly from an interactive shell; you need to use wait instead for scripts. –  Trevor Robinson Aug 20 '13 at 19:47

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.