I need to ask this question just to double check the answer.
Does the order of the commands matter? For example:
Is this command
taskset 0x2 time echo "foo"
equal than
time taskset 0x2 echo "foo"
?
I need to know if all the commands followed by the taskset will have the same CPU affinity or just the command immediately after it.
Here is a little experiment:
Start two BG tasks
Get their PIDs
Get the CPU affinity of the known PIDs:
So, it seems like the CPU affinity is set for the first process only.
Update (trying to explain the following behavior):
/usr/bin/time taskset 0x2 sleep 100000
=> onlysleep
gets the affinity mask2
(somewhat expected!)taskset 0x2 /usr/bin/time sleep 100000
=> bothtime
andsleep
get the affinity mask2
(need to clarify!)In the second case, let's call
ps -f
to get the PPID (parent PID) for each process:What can be seen is that
sleep
's PPID (5942) corresponds to/usr/bin/time
's PID (5942). IOWsleep
is a child process of (has been forked from)/usr/bin/time
. Because any child process inherits the configuration of the parent process,sleep
will have the same CPU affinity with/usr/bin/time
.