How to start a process with a nice value of -20 and not give it root privilege

nicepriorityprocess

I would like to start a process with a nice value of -20. This requires me to use a command like – sudo nice -n -20 matlab. However, this starts matlab as root too. Is there a way to have matlab as non-root?

My current approach is –sudo nice -n -20 sudo -u myusername matlab – which, to me looks like a hack. Is there a direct approach to do this?

Best Answer

I would start it normally and use "renice" afterwards...

However I was able to make a quick hack together with "su" which works:

sudo nice -n -20 su -c command_to_run user_to_run_as

(If you don't have to give sudo a password - perhaps because you've already just given it - you may add an "&" to put the whole thing in the background.)

Since you already become root with the sudo-command, su won't ask you for a password. I was able to start a X-program from a terminal-emulator under X. If you want to run the X-program as another user than the user owning the X-session, you'll probably need to explicitly tell X to allow it (open for X-clients from that user).