#define _GNU_SOURCE #include #include #include /* Usage: ./schedtest */ int miliseconds() { struct timeval tv; gettimeofday(&tv, 0); return tv.tv_usec/1000; } int main(int argc, char *argv[]) { int lives = 1000, time, lasttime, childs, cores = 2; if (argc > 1) cores = atoi(argv[1]); childs = cores * 2; while (childs-- && !fork()); while (lives) { time = miliseconds(); if (lasttime != time && sched_getcpu() != (cores-1)) lives--; lasttime = time; } return 0; }