#include #include #include #include #include #include #define SYS_TASK_INFO 280 #define SYS_HELLOWORLD 281 FILE *fp = NULL; typedef struct { long state; int pid, tgid; unsigned long utime, stime; int prio, static_prio; unsigned long sleep_avg; unsigned int time_slice, first_time_slice; } task_info_struct; void CPU_burst(int times) { double x = 1, y = 2, z = 1.5; int i, j, k; for (i = 0; i < times; i++) for (j = 0; j < 10000; j++); for (k = 0; k < 10000; k++) { x = y*z/x; y = x; } } void IO_burst(int nblocks) { char temp[1024]; int i; long file_size, read_pos; if (!fp) { fp = fopen("test.txt", "r"); fseek(fp, 0, SEEK_END); file_size = ftell(fp); } for (i = 0; i < nblocks; i++) { read_pos = (float)rand()/RAND_MAX*file_size - 1024; fseek(fp, read_pos, SEEK_SET); fread(temp, 1, 1024, fp); } } int main() { int n = 0; task_info_struct task_info; int ret; while(1) { CPU_burst(100); IO_burst(100); sleep(1); ret = syscall(SYS_TASK_INFO, &task_info); if (!ret) { printf("\n"); printf("process [%d : %d] State = %s \n", task_info.pid, task_info.tgid, (task_info.state==0)? "Running" : "Blocked"); printf("utime = %ld stime = %ld \n", task_info.utime, task_info.stime); printf("prio = %d static_prio = %d sleep_avg = %ld\n", task_info.prio, task_info.static_prio, task_info.sleep_avg); } } return 0; }