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?


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

  • 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.


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 &
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.

  • 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

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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