# Inheritance of `nice`?



## michaelsanford (May 31, 2008)

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

Given

```
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* ?


----------



## Mikuro (May 31, 2008)

michaelsanford said:


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


----------



## artov (May 31, 2008)

About "sudo nice" vs "nice sudo":

Normal user cannot use lower the nice value, so following works:



> $ sudo nice -n 10 theprogram



but following does not



> $ nice -n 10 sudo theprogram


----------



## michaelsanford (May 31, 2008)

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

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


----------



## Mikuro (May 31, 2008)

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:
	
	



```
sudo ps -xww -o pid,command,nice
```


----------



## macbri (May 31, 2008)

Here's a quick-n-dirty test:


```
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]


----------

