Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I taskset a process inside container/docker?

Tags:

docker

taskset

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.

like image 326
qudongfang Avatar asked Sep 06 '25 03:09

qudongfang


1 Answers

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
}
like image 179
qudongfang Avatar answered Sep 09 '25 04:09

qudongfang