Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "types.h"
- #include "stat.h"
- #include "user.h"
- #include "uproc.h"
- // create maxprocs const
- #define MAXPROCS 64
- int main(int argc, char *argv[]) {
- // create uproc struct with MAXPROCS entries
- struct uproc *uproc = malloc(MAXPROCS*sizeof(struct uproc));
- // get the number of processes currently running
- int proc_num = getprocs(MAXPROCS, uproc);
- // if an error ocurs during getprocs, deal with it here based on error code
- if (proc_num == -1) {
- // int pass error occurred, print appropriate statement and exit
- printf(1, "Kernel returned an error while passing an integer.\n");
- exit();
- } else if (proc_num == -2) {
- // ptr pass error occurred, print appropriate statement and exit
- printf(1, "Kernel returned an error while passing a pointer.\n");
- exit();
- }
- // iterate through the number of currently-running processes
- // for each process, determine if the pid is the root
- // once root is found, determine if they are connected to the root
- // else, print at third level
- // declare counter i and set to zero
- int i = 0;
- for (; i < proc_num; i++) {
- if (uproc[i].pid == 1) {
- // this is the root node, print as such
- printf(1, "%s[%d]\n", uproc[i].name, uproc[i].pid-1);
- } else if (uproc[i].ppid == 1) {
- // this is a CHILD of the root node, print as such
- printf(1, "%8s[%d]\n", uproc[i].name, uproc[i].pid-1);
- } else {
- // this is NOT a root node NOR is it a child of root
- // print out generic
- printf(1, " %s[%d]\n", uproc[i].name, uproc[i].pid-1);
- }
- }
- // process is done, end now
- exit();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement