Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static void printOutput() {
- //Layout the output table's first column
- p1putstr(STDOUT_FILENO, "\npid\tcmd\tstatus\tstate\tutime\tstime\tpriority\tvsize\texit code\n");
- for (int i=0; i < procNum; i++) {
- char path[100];
- path[0] = '\0';
- // Create path to /proc/current_pid/stat to open
- p1strcat(path, "/proc/");
- p1strcat(path, p1itoa(procs[i].pid));
- p1strcat(path, "/stat");
- char state[4];
- state[0] = '\0';
- char utime[32];
- utime[0] = '\0';
- char stime[32];
- stime[0] = '\0';
- char priority[8];
- priority[0] = '\0';
- char vsize[8];
- vsize[0] = '\0';
- char exitc[32];
- exitc[0] = '\0';
- printf("This is the current path: %s\n", path); //TEST
- int fd = open(path, O_RDONLY);
- printf("This is the current fd: %d\n", fd);
- if (fd > 0) {
- char stat[512];
- long count = read(fd, &stat, 512);
- stat[count] = '\0';
- stat[p1strlen(stat)-1] = '\0'; //remove New Line Symbol from final path
- int index = 0;
- int statIndex = 1;
- do {
- char word[64];
- index = p1getword(stat, index, word);
- printf("This is the current index on line 151: %d\n", index);
- if (index == -1) {
- break;
- }
- printf("This is the current statIndex on line 171: %d\n", statIndex);
- if (statIndex == 3) {
- p1strcat(state, word);
- } else if (statIndex == 14) {
- p1strcat(utime, word);
- } else if (statIndex == 15) {
- p1strcat(stime, word);
- } else if (statIndex == 18) {
- p1strcat(priority, word);
- } else if (statIndex == 23) {
- p1strcat(vsize, word);
- } else if (statIndex == 52) {
- p1strcat(exitc, word);
- }
- statIndex++;
- printf("This is the current statIndex on line 171: %d\n", statIndex);
- } while (index >= 0);
- close(fd);
- }
- p1putint(STDOUT_FILENO, procs[i].pid);
- p1putstr(STDOUT_FILENO, "\t");
- char cmd[32];
- p1getword(procs[i].command, 0, cmd);
- p1putstr(STDOUT_FILENO, cmd);
- p1putstr(STDOUT_FILENO, "\t");
- if (procs[i].procStarted == 1) {
- p1putstr(STDOUT_FILENO, "started");
- } else if (procs[i].procRunning == 1) {
- p1putstr(STDOUT_FILENO, "running");
- } else if (procs[i].procRunning != 1 && procs[i].procEnded != 1) {
- p1putstr(STDOUT_FILENO, "suspended");
- } else if (procs[i].procEnded == 1) {
- p1putstr(STDOUT_FILENO, "terminated");
- }
- p1putstr(STDOUT_FILENO, state);
- p1putstr(STDOUT_FILENO, "\t");
- p1putstr(STDOUT_FILENO, utime);
- p1putstr(STDOUT_FILENO, "\t");
- p1putstr(STDOUT_FILENO, stime);
- p1putstr(STDOUT_FILENO, "\t");
- p1putstr(STDOUT_FILENO, priority);
- p1putstr(STDOUT_FILENO, "\t");
- p1putstr(STDOUT_FILENO, vsize);
- p1putstr(STDOUT_FILENO, "\t");
- p1putstr(STDOUT_FILENO, exitc);
- p1putstr(STDOUT_FILENO, "\n");
- }
- p1putstr(STDOUT_FILENO, "\n");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement