Created
January 16, 2024 07:30
-
-
Save nomeaning777/0107b023f379ac87d7cca97eff59a332 to your computer and use it in GitHub Desktop.
List up the threads of a specific process and their CPU affinity
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/python3 | |
import os | |
import sys | |
for pid in sys.argv[1:]: | |
path = '/proc/' + pid + '/task' | |
if os.path.exists(path): | |
for tid in sorted(os.listdir(path)): | |
with open(f"{path}/{tid}/comm", 'r', encoding='utf-8') as r: | |
thread_name = r.read().strip() | |
print(f"TID={tid} Name={thread_name} Affinity={os.sched_getaffinity(int(tid))}") | |
else: | |
print(f'PID: {pid} not found', file=sys.stderr) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment