Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I need to run dosemu with nice --20 from script. Problem is: a negative value can be applied only with sudo.

Do you know any way to run nice command without sudo or simply run nice --20 dosemu from script?

share|improve this question
    
It's unsecure. It's better to be a root. –  ZDroid Jun 25 '13 at 10:29

3 Answers 3

Unfortunately, I don't think that's easily doable.

If your dosemu process runs as a separate user, then you can set the priority of all processes of that user to a negative value using /etc/security/limits.conf.

EDIT: silly me, you cannot create a suid shell script, that just doesn't work.

EDIT2: OK, you can configure sudo such that it does not require you to give password when someone from the sudo group runs nice or renice. In a terminal window, enter

sudo visudo

This will open a simple text editor that will edit the configuration of sudo. Add the following line at the end of the file:

%sudo   ALL = (ALL) NOPASSWD: /usr/bin/nice,/usr/bin/renice

Exit the editor. The editor will make sure that the syntax is correct (otherwise one could break the system). Now, you can run

sudo nice -n -20 sudo -u $USER /some/program

and you will not get prompted for a password. In fact, nice will start another process called sudo with the -20 priority. This new sudo process will switch back to your original user (-u $USER, otherwise you would run the /some/program as root) and starts /some/program.

share|improve this answer

try this:

sudo -k nice -n -20 su -c "dosemu" $USER

while it is running, run this:

ps -A --forest -o pid,user,command |grep dosemu

you will see that nice was run with root privileges, but dosemu was run as normal $USER.

Understandind how safe it is: to make it sure that there is no flaw, try this where you will see it asks the password 2 times because sudo ls is run as normal $USER, so a script with sudo on it wont work unseen:

sudo -k nice -n -5 su -c "sudo ls" $USER

and this will ask password one time only as it is already root to sudo ls:

sudo -k nice -n -5 su -c "sudo ls" root

PS.: instead of dosemu, for tests, I used sleep 120, and sudo -k is for increased safety.

share|improve this answer

Try: sudo -s -H

It logs you in as root after which you won't need the sudo.

Then run your script.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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