[CentOS] OT: Howto to capture taskset output command

John Doe jdmls at yahoo.com
Wed Feb 26 13:51:02 UTC 2014


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



More information about the CentOS mailing list