awkkshpstaskset

ksh cmd one-liner to grep for several PIDs at once


I got a bunch of processes that I need to check CPU affinity for, so I got this one liner:

for i in `ps -Fae | grep proc_name| awk '{print $2}'`; do taskset -acp $i;done

but I have a problem, taskset shows all the child processes' pid too so I get a massive line of numbers along with their cpu affinity.

I want to pipe the above line into an egrep 'pid1|pid2' so I can filter out all the child processes.

I tried to this: for i in `ps -Fae | grep proc_name| awk '{print $2}'`; do taskset -acp $i;done | xargs egrep 'ps -Fae | grep proc_name| awk '{print $2}''

but my ksh shell didn't like the awk brackets at all.

So I have two questions:

  1. can taskset be changed to show only parent pid?
  2. how do I write the last bit where I egrep only the parent pid?

Solution

  • Filter inside the loop:

    for i in $(ps -Fae | grep proc_name| grep -v grep | awk '{print $2}'); do
       taskset -acp "$i" | grep "$i"
    done