Inheritance of `nice`?

michaelsanford

Translator, Web Developer
I make very frequent use of nice values. I was wondering how nice is inherited through subsequent processes, though.

Given
Code:
nice open /Applications/Firefox.app
I understand that this will call `open` with a nice value > 0, but will it ALSO call Firefox with a nice value > 0?

What about something using sudo. What's the preferred ordering: sudo nice or nice sudo ?
 
I understand that this will call `open` with a nice value > 0, but will it ALSO call Firefox with a nice value > 0?
Not on my system. I assume this is because 'open' does not launch child processes, but instead goes through launchd. So while niceness is normally inherited, it can sometimes be hard to know when a process will really be launched as a child process.

As for sudo....I have no idea! I guess 'sudo nice' would allow you to set negative niceness values as well, though, so that could be a plus (I haven't tested it myself).
 
I know that a normal user can't lower a nice value. I may have not been explicit enough in my explanation. Note above that I indicated "nice > 0" meaning a positive (increased) value.

I wanted to know whether issuing
Code:
nice sudo fink selfupdate
will increase the nice value (i.e., to nice value > 0) of fink as well, or if it will only increase the nice value of sudo, but that sudo will subsequently call fink with nice = 0.
 
I just gave it a test, and sudo will pass down its niceness, so yes, 'nice sudo' will work. And nice will pass down its user, so 'sudo nice' will also work. As far as I can tell there should be no significant difference between the forms, unless, as I said, you want to give a negative niceness.

You can check the niceness of running processes easily like this:
Code:
sudo ps -xww -o pid,command,nice
 
Here's a quick-n-dirty test:

Code:
sleep 60 &
nice -n 15 sudo sleep 60 &
sudo nice -n 15 sleep 60 &
ps -al | grep [s]leep | awk '{print $1,$2,$6}'

This returns the UID, PID and nice value of each sleep command. The first will be have your UID and a nice value of 0, the other two will be running as root with nice value 15. So whether nice comes before sudo or after, the end result looks the same (OS X 10.4.11 anyway).

[Edit]Snap![/Edit]
 
Back
Top