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 Answers3

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

maxelost
  • 3,205
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.

LaC
  • 3,019