barp
barp

Reputation: 6929

How can I set niceness and process affinity at the same time?

Is there a way to set the nice value of process and its affinity at the same time? For example:

 taskset -c 0,1 nice -20 proc

Update: It works like this. I thought it must me something more complex.

Upvotes: 9

Views: 3534

Answers (2)

Todd A. Jacobs
Todd A. Jacobs

Reputation: 84363

Using PID-Based Scheduling Tools

Many CPU scheduling tools want a PID rather than a command. The following seems to work on my system:

# Using shell expansion to reliably use correct PID.
sudo nice -n18 schedtool -a 0,1 $(sleep 30 & echo $!) &

by using a shell expansion to get the PID of the last backgrounded process, but it seems hackish. The following seems cleaner, IMHO, but your mileage (and obviously the specifics of the scheduling tool you're using) may vary.

# Cleaner example with less hacking around.
nice -n18 sleep 30 &
sudo schedtool -a 0,1 $!

Flags That Take Commands

If supported, the -e flag seems to do what's needed by allowing a command instead of a PID. For example:

sudo schedtool -a 0,1 -e nice -n18 sleep 30 &

Upvotes: 2

Spencer Rathbun
Spencer Rathbun

Reputation: 14900

What's wrong with taskset -c 0,1 && nice -20 proc? If taskset succeeds, then nice will be called.

Upvotes: 0

Related Questions