Created
March 13, 2024 17:02
-
-
Save TunaCici/9cc2e3fd1199f07fef001d718b776eee to your computer and use it in GitHub Desktop.
[GNU/Linux] Get All Threads & Core Affinities of a Process w/o ps or taskset
This file contains 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
#!/usr/bin/env bash | |
if [ $# -eq 0 ]; then | |
echo "Usage ./get-affinities.sh <PID>" | |
exit 1 | |
fi | |
pid=$1 | |
if [ ! -d "/proc/${pid}" ]; then | |
echo "Process with PID ${pid} does not exist." | |
exit 1 | |
fi | |
name=$(cat /proc/${pid}/comm) | |
echo "[x] ${pid} (${name})" | |
for tid in $(ls /proc/${pid}/task/); do | |
status="/proc/${pid}/task/${tid}/status" | |
if [ -e "$status" ]; then | |
name=$(cat /proc/${pid}/task/${tid}/comm) | |
affinity=$(cat ${status} | grep -w "Cpus_allowed_list" | grep -oE '[0-9,-]+') | |
echo "[x] \-- ${tid} ${name}, Core Affinity: ${affinity}" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment