Can I taskset a process inside container/docker?

1.8k Views Asked by At

Can I taskset a process inside container/docker? How can I tell which cpu cores are assigned to this container?

I want to taskset a process to some specific cpu cores to get better performance.

1

There are 1 best solutions below

0
On

I got a simple solution that just works.

# shell function which gets the last `taskset`able cpu core 
findLastUsableCore() {
    count=`grep -c ^processor /proc/cpuinfo`

    count=$((count - 1))
    while [ "${count}" -ge "0" ] ; do
        taskset -c ${count} echo >/dev/null 2>&1

        if [ "$?" -eq "0" ];then
            return ${count}
        fi

        count=$((count - 1))
    done

    return 0
}