From output of man sched_getcpu
:
NAME
sched_getcpu - determine CPU on which the calling thread is running
SYNOPSIS
#define _GNU_SOURCE
#include <utmpx.h>
int sched_getcpu(void);
DESCRIPTION
sched_getcpu() returns the number of the CPU
on which the calling thread is currently executing.
RETURN VALUE
On success, sched_getcpu() returns a non-negative CPU number.
On error, -1 is returned and errno is set to indicate the error.
SEE ALSO
getcpu(2)
Unfortunately, this is Linux specific. I doubt there is a portable way to do this.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…