shell/ticks.c (view raw)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
#include "cedos.h"
#include "stdio.h"
#include <stdint.h>
#include "stdlib.h"
#include "string.h"
#include "cedos.h"
void main(char *args) {
if (args == NULL || strlen(args) == 0) {
int ticks = sc_time_get_ticks();
printf("%i\n", ticks);
} else {
int interval = atoi(args);
if (interval <= 0) {
printf("Invalid interval value.\n");
return;
}
int pid = get_pid();
int color = 40 + (pid % 8);
int superticks = 0;
while (1) {
int ticks = sc_time_get_ticks();
if (ticks / interval != superticks) {
printf("\e[%im\e[0K[%i] %i ticks\e[0m\n", color, pid, ticks);
superticks = ticks / interval;
}
sleep(interval);
}
}
}