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

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


One step further @Jordan, Here's the elegant solution against sudo nice -n -xx su <username> -c matlab hack

Note: Using username=sid, matlab meta-data dir=/var/lib/matlab, nice=-10 change at your will

  1. Create matlab meta-data dir(PERPARE)

    sudo mkdir /var/lib/matlab

  2. Add specified user to launch matlab & right persimisson

    sudo useradd -d /var/lib/matlab sid
    sudo chown sid:sid /var/lib/matlab
  1. Set user(sid) password

    sudo passwd sid

  2. Append following to /etc/security/limits.conf

    sid - priority -10

  3. Setup & copy ssh-key to automate login(OPTIONAL)

    ssh-keygen -t rsa #following key passwd misc   
    ssh-copy-id sid@localhost #using sid's passwd
  1. Create matlab shell wrapper(fix silent fail ERR)
    sudo -i
    cat <<EOF >>/usr/local/bin/wmatlab
    #!/bin/bash --
    # A wrapper to launch matlab
    /usr/local/MATLAB/<version>/bin/matlab -desktop
    EOF
    chmod +x /usr/local/bin/wmatlab
  1. Ajust sid's login shell

    sudo usermod -s /usr/local/bin/wmatlab sid

  2. start matlab using ssh with Xforward

    ssh -X sid@localhost


I have found this could be done by modifying the file /etc/security/limits.conf (at least on some linux distros). In my case, I simply added:

#<domain>    <type>  <item>  <value>
my_user        -     nice       -20`

then you can execute

nice -n -20 matlab

Logout and back in after saving changes to /etc/security/limits.conf.

This answer explains why.