Created
March 15, 2023 09:20
-
-
Save nutrino/3cc524c797f3908eb8c5fdf9f1cb3b21 to your computer and use it in GitHub Desktop.
Set unmatched CPU affinity with the help of the ChatGPT
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Use a while loop to read each line of output from ps | |
while read -r line; do | |
if [[ $line == *-cpu* ]]; then | |
#echo "$line" | |
pid=$(echo $line | awk '{print $1}') | |
no=$(echo $line | awk '{print $2}') | |
cmd=$(echo $line | awk '{$1=$2=""; print $0}') | |
cpu=$(echo $cmd | grep -oE '\-cpu [0-9]+' | awk '{print $2}') | |
if [[ "$no" != "$cpu" ]]; then | |
echo "PID: $pid, REALCPU: $no, CPUID: $cpu" | |
taskset -cp $cpu $pid | |
fi | |
fi | |
done < <(ps -ax -o pid,psr,cmd) |
ps_by_cpuid.sh
#!/bin/bash
CPUID=$1
ps -eo pid,psr,pcpu,command | awk 'NR>1' | awk -v cpuid="$CPUID" '$2 == cpuid' | sort -k3,3n
mpstat -P ALL
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
top_by_cpuid.sh