| @@ -0,0 +1,20 @@ | |||
| 1 | + | #define _GNU_SOURCE | |
| 2 | + | #include <stdio.h> | |
| 3 | + | #include <sched.h> | |
| 4 | + | #include <errno.h> | |
| 5 | + | #include <unistd.h> | |
| 6 | + | ||
| 7 | + | int main() { | |
| 8 | + | cpu_set_t my_set; | |
| 9 | + | int pid = 1; | |
| 10 | + | int affinity = sched_getaffinity(pid, sizeof(cpu_set_t), &my_set); | |
| 11 | + | printf("cpuset of pid %d is %0.12x\n", pid, my_set); | |
| 12 | + | printf("cpuset of pid %d: ", pid); | |
| 13 | + | for (int i = 0; i < CPU_COUNT(&my_set); i++) { | |
| 14 | + | printf("%d", CPU_ISSET(i, &my_set) ? 1 : 0); | |
| 15 | + | if (i % 32 == 31) printf(" "); | |
| 16 | + | } | |
| 17 | + | printf("\n"); | |
| 18 | + | printf("errno: %d\n", errno); | |
| 19 | + | return 0; | |
| 20 | + | } | |
aquafire / test_cpu_affinity.c
Last active 6 months ago
aquafire revised this gist 9 months ago · 10ca540
1 file changed, 20 insertions