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.
On Wed, Feb 26, 2014 at 6:57 AM, C. L. Martinez <carlopmart at gmail.com>wrote:> if [ "$cpu_affinity" == "$cpu_affinity_ok" ]; then >are you comparing strings or integers? # man test STRING1 = STRING2 the strings are equal INTEGER1 -eq INTEGER2 INTEGER1 is equal to INTEGER2
From: C. L. Martinez <carlopmart at gmail.com>> 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: > > As you can see, function compare under "if" statement doesn't > works ...This works for me: function cpu_affinity() { ? taskset -p -c $1 | awk ' { print $6 } ' } and PID=`cat /tmp/test.pid` if [ $(cpu_affinity $PID) -eq $cpu_affinity_ok ]; then JD