Files
linux-kernel-module-cheat/userland/c/infinite_loop.c
Ciro Santilli 六四事件 法轮功 d1d12e4b43 infinite_loop.c: document better, allow 0 magic value to not print
Enable test by passing arguments to the test to limit loops.

gem5 arm LSE: still skipped, but add a link to the master patch that was merged.
2019-09-07 00:00:00 +00:00

46 lines
999 B
C

/* https://cirosantilli.com/linux-kernel-module-cheat#c
*
* Loop and print an integer whenever a period is reached:
*
* ....
* ./infinite_loop [period=100000000 [max=0]]
* ....
*
* * period: period for printing integers to stdout
* 0 means disable printing.
* * max: Stop counting when max is reached.
* 0 means count to infinity.
*/
#include <inttypes.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv) {
uintmax_t i, j, period, max;
int max_given;
if (argc > 1) {
period = strtoumax(argv[1], NULL, 10);
} else {
period = 100000000;
}
if (argc > 2) {
max = strtoumax(argv[2], NULL, 10);
max_given = 1;
} else {
max_given = 0;
}
i = 0;
j = 0;
while (1) {
i++;
if (period != 0 && i % period == 0) {
printf("%ju\n", j);
j++;
}
if (max_given && i == max)
break;
}
}