Starting from:
$35

$29

Project #1 - 537ps command solution

Description

This assignment is to write a simple version of the ps command. This version of ps, called 537ps, can be executed from a command line. It will read a variety of information about one or more running programs (processes) on the computer, and then display that information. As an example of what the program does, consider a command such as:




537ps -p 1234 -s -S -U -v -c




This runs the ps command, and displays the status letter (in this case, running), amount of user time, and the command line for process 1234. The output looks like: 1234: R utime=150 stime=150 vmemory=11000 [myprog -x -y file1 myoption]




## Included Files

main.c

This is the main routine of the program. In this file the main function is invoked and the command line args and passed on to be converted into an argument holder structure. This returned struture is then passed on to be processed and printed accordingly.




options_processing.c

This file takes in the command line arguments as parameters and parses and converts them into and argument holder structure. If none of the arguments are invalid this structure is then returned to the main routine.




options_processing.h

This is the header file for options_processing.c that contains the method arguments and the ArgumentHolder structure initialization.




process_list.c

This file takes in the argument holder structure and depending on the value of the pFlag, either parses all directories in /proc and passes its path on to be printed if they belong to the current user, or finds the specfied directory and passes its path on to be printed regardless of which user it belongs to.




process_list.h

This is the header file for process_list.c that contains the method arguments for this file.




stat_file_parser.c

This file takes in the path of the directory to be printed as well as the argument holder structure and opens its status, stat, statm, and cmdline files to retrieve and print the data specified by the argument holder.




stat_file_parser.h

This is the header file for stat_file_parser.c that contains the method arguments for this file.




Makefile

This file, invoked with the command 'make', compiles all the preceding files into one executable named '537ps'.




## Usage

The program can be invoked with the command '537ps' followed by any of the following options:




-p [pid]

Display process information only for the process whose number is pid. It does not matter if the specified process is owned by the current user. If this option is not present then display information for all processes of the current user (and only of the current user).




-s

Display the single-character state information about the process. This option defaults to be **false**, so if it is not present, do not display this information. -s- is valid but has no effect.




-U

Display the amount of user time consumed by this process. This option defaults to be **true**, so if it is not present, then this information is displayed. -U- turns this option off.




-S

Display the amount of system time consumed so far by this process. This option defaults to be **false**, so if it is not present, then this information is not displayed. -S- is valid but has no effect.




-v

Display the amount of virtual memory currently being used (in pages) by this program. This option defaults to be **false**, so if it is not present, then this information is not displayed. -v- is valid but has no effect.




-c

Display the command-line that started this program. This option defaults to be **true**, so if it is not present, then this information is displayed. -c- turns this option off.

More products