//File: listproc.java //CS 471 - Operating Systems Project //Dennis Pereira, Ely Soto, John Cavalieri //The listproc command is a command that lists all of the processes that are being //executed by the user issuing the command //Listproc displays the name and the handle for the command //This command accepts arguments to list the processes of all users (-a) public class listproc extends VMachine { public listproc() { } public void run() { try { int proccount = 0; User tuser; //if there are no args then do the default //display the processes running for the user if(args.length == 0) { sysapi.Write(OUT,"Processes owned by -" + owner + "-\n"); //for each process write the process name and handle ID proccount = sysapi.findUser(owner).getCount(); for(int i = 0; i < proccount; i++) { sysapi.Write(OUT,sysapi.findUser(owner).get(i).getID() + "\n"); } } //if the argument is -a then, display the processes owned all users else if(args[0].toLowerCase().compareTo("-a")==0) { //loop for each user for(int i=0; i < sysapi.getUserCount(); i++) { //get the user name tuser = sysapi.getUser(i); sysapi.Write(OUT,"\nProcesses owned by -" + tuser.getName() + "-\n"); //Dangerous because Count may decrease between calls proccount = tuser.getCount(); //loop for each of the users processes for(int x = 0; x < proccount; x++) { //print process name and handle ID sysapi.Write(OUT,tuser.get(x).getID() + "\n"); } } } } catch (Exception err) { //some type of error happened System.out.println("ListProc threw an Exception."); } sysapi.Exit(vmh,owner); } }