#include #include #include #include #define NUM_THREAD 4 #define STACK_SIZE 4000 #define LOOP_STOP 1000 /* stacks */ void* stack[NUM_THREAD][STACK_SIZE]; /* log thread pids */ int pids[NUM_THREAD]; void report_proc_time(int pid) { char fname[80]; FILE* procf; char cmd[80]; unsigned long utime, stime; sprintf(fname, "/proc/%d/stat", pid); procf = fopen(fname, "r"); if (procf == NULL) { printf("failed to open file %s\n", fname); assert(0 ==1); } fscanf(procf, "%d %s %*c %*d %*d %*d %*d %*d %*lu %*lu %*lu %*lu %*lu %lu %lu", &pid, cmd, &utime, &stime); printf("pid=%d, cmd: %s, time(ms): %lu, utime(ms): %lu, stime(ms): %lu\n", pid, cmd, (utime+stime)*10, utime*10, stime*10); fclose(procf); } void report_time(void) { int i; printf("-----------------------------------------\n"); for (i=0; i< NUM_THREAD; i++) report_proc_time(pids[i]); } int loop (void *arg) { /* determine number of clones */ int i; int x=(int)arg; pids[x] = getpid(); /*closed loop */ for(;;) { for (i=0; i