taskset设置CPU affinity

 

 

Retrieve or set a processes's CPU affinity(亲和).

This requires sched_{g,s}etaffinity support in your libc.

 

 

1. busybox

cd ~/source-code/mc40/buildroot-2020.02.8

make busybox-menuconfig

 

Linux System Utilities  —>

    [*] taskset (4.2 kb)

 

 

2. make

make -j8

/output/target/usr/bin/taskset

 

 

3. uasge

/ # taskset –help

BusyBox v1.31.1 (2020-12-03 14:56:00 CST) multi-call binary.

Usage: taskset [-p] [HEXMASK] PID | PROG ARGS

Set or get CPU affinity

        -p      Operate on an existing PID

 

3.1 在特定CPU运行应用

taskset cpu prog

 

taskset 1 ping 10.126.11.254 -c 10 &

taskset 2 ping 10.126.11.254 -c 10 &

taskset 4 ping 10.126.11.254 -c 10 &

taskset 8 ping 10.126.11.254 -c 10 &

 

run ping at cpu3:

taskset 8 ping 10.126.11.254 -c 10 &

 

3.2为已经运行的应用切换CPU

taskset -p cpu pid

1) ping is running at cpu2

2) switch to cpu1

taskset -p  2 1389

 

 

创作挑战赛新人创作奖励来咯,坚持创作打卡瓜分现金大奖

Published by

风君子

独自遨游何稽首 揭天掀地慰生平