[CentOS] OT: Howto to capture taskset output command

Wed Feb 26 11:57:25 UTC 2014
C. L. Martinez <carlopmart at gmail.com>

Hi all,

 I am trying to set processor affinity for a specific process using a
shell script without result. Script:

#!/bin/sh -x

cpu_affinity_ok="2"
cpu_affinity="taskset -p -c `cat /tmp/test.pid` | awk '{print $6}'"

if [ -f /tmp/test.pid ]; then
    if [ "$cpu_affinity" == "$cpu_affinity_ok" ]; then
       exit 0
     else
        taskset -p -c 2 `cat /tmp/test.pid`
     fi
fi

This script doesn't works:

[root at cos01 bin]# taskset -p -c 27756
pid 27756's current affinity list: 2

Excecuting script:

[root at cos01 bin]# ./my_cpu_affinitty
+ cpu_affinity_ok=2
++ cat /tmp/test.pid
+ cpu_affinity='taskset -p -c 27756 | awk '\''{print }'\'''
+ '[' -f /tmp/test.pid ']'
+ '[' 'taskset -p -c 27756 | awk '\''{print }'\''' == 2 ']'
++ cat /tmp/test.pid
+ taskset -p -c 2 27756
pid 27756's current affinity list: 2
pid 27756's new affinity list: 2

 As you can see, function compare under "if" statement doesn't works ...

Any idea??

Thanks.