Junior — Middle
How can you determine on which core the current operating system is running?
sobes.tech AI
Answer from AI
Determining which core the current operating system is running on can be done in several ways, depending on the OS and tools. In Linux, for example, you can look at the file /proc/self/stat, where field 39 contains the core number on which the current thread is running. You can also use the system call sched_getcpu() in C or similar functions in other languages, which return the CPU number on which the current process is running.
Example in C:
#include <stdio.h>
#include <sched.h>
int main() {
int cpu = sched_getcpu();
printf("Current process is running on core: %d\n", cpu);
return 0;
}