You are not logged in.

#1 2008-09-22 16:56:56

lardon
Member
Registered: 2008-05-31
Posts: 264
Website

Recursive nice?

Hi all,

I was wondering if there was any way to recursively set nice priorities on a process. By default, when you "nice" a process, it doesn't change the priorities of its children. So is there way to do so without heavy scripting? Or would any of you have such a script at their disposition?


Autojump, the fastest way to navigate your filesystem from the command line!

Offline

#2 2008-09-23 04:51:09

B-Con
Member
From: USA
Registered: 2007-12-17
Posts: 554
Website

Re: Recursive nice?

$ ps --ppid YOUR_PID | grep -v "PID" | awk '{print $1}' | xargs nice -YOUR_NICE_VALUE YOUR_PID

I think that will do it. Just list all of the process's children, then parse the pid's out and send them into nice.

[edit]
Added the YOUR_PID on the end so that this would effect the parent process as well.

Last edited by B-Con (2008-09-23 04:53:10)

Offline

#3 2008-09-23 07:20:48

lardon
Member
Registered: 2008-05-31
Posts: 264
Website

Re: Recursive nice?

B-Con wrote:

$ ps --ppid YOUR_PID | grep -v "PID" | awk '{print $1}' | xargs nice -YOUR_NICE_VALUE YOUR_PID

That doesn't work because it stops at the direct children of the process you pass in, so it's not recursive.


Autojump, the fastest way to navigate your filesystem from the command line!

Offline

#4 2008-09-23 12:01:56

Profjim
Member
From: NYC
Registered: 2008-03-24
Posts: 658

Re: Recursive nice?

OK, then, do:

function rnice {
nice -n $1 $2
for child in $(ps --ppid $2 -o pid=); do
rnice $1 $child
done
}

Offline

#5 2008-09-23 14:05:41

lardon
Member
Registered: 2008-05-31
Posts: 264
Website

Re: Recursive nice?

Very nice, thanks!


Autojump, the fastest way to navigate your filesystem from the command line!

Offline

Board footer

Powered by FluxBB