4

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?

3 Answers 3

4

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

1
  • Thank you kindly. I can set the minimum priority for the user to -10, and skip using sudo completely. Jan 21, 2011 at 18:25
1

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.

1

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.

3
  • This would work, but I think it's even more awkward than the answer I gave (sudo nice -10 sudo -u user command) Jan 21, 2011 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. Aug 20, 2013 at 19:38
  • Also note that fg can only be used directly from an interactive shell; you need to use wait instead for scripts. Aug 20, 2013 at 19:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .