简体   繁体   中英

Can I taskset a process inside container/docker?

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.

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
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM