Linux:查看线程运行于哪个CPU核心上
线程是最小的执行调度单元,线程执行于某个CPU核心之上,或者说某个CPU核心执行此线程。
如何查看某线程运行于哪个CPU核心上呢?
ps -eLF 查找 PSR 字段值
ps -eLF
UID PID PPID LWP C NLWP SZ RSS PSR STIME TTY TIME CMD
root 1 0 1 0 1 4836 1548 2 Feb25 ? 00:00:02 /sbin/init
root 2 0 2 0 1 0 0 2 Feb25 ? 00:00:00 [kthreadd]
root 3 2 3 0 1 0 0 0 Feb25 ? 00:00:00 [migration/0]
……
#define _GNU_SOURCE#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <pthread.h>void *start_routine(void *arg) {const char *msg = "thread: i am thread";while (1) {write(1, msg, strlen(msg));sleep(1);}
}int main(