Each student will write a Bash script which provides information to the user comparing the statuses of processes and or threads. Also to be included is a detailed report using the attached format The...

1 answer below »

Each student will write a Bash script which provides information to the user comparing the statuses of processes and or threads. Also to be included is a detailed report using the attached format


The specific information to be provided to the user will be determined by the student, but must include at least three different values.


The script will use the information from the /proc directory to provide the output.


The script will support multiple uses, which will include a help option which will display basic usage information.


Some examples of comparisons the script may perform:


- Display the two processes most nearly identical in terms of run-time, memory size, etc.


- Display the processes which closely match specific input parameters for process attributes.


- Display processes which were launched from a particular directory or directory tree, or which were launched from similar locations.


- Display processes in adjacent or nearly adjacent memory locations.


- Display processes where Usernames have matching characteristics.


- Create an on-going list of all process names which have been used on the system.


The script must allow for and use at least 2 command line arguments (in addition to help).



  • The command line arguments may either be used as a part of the determination (e.g. user or dates)

  • Or, to change the behavior of the script (e.g. count remote vrs. local access).


The script must include at least one function.


The script will follow the “Scripting Best Practices” as provided.



Scripting Best Practices


When run with inappropriate arguments, scripts should print a usage message and exit. The same message could be printed with a–helpargument.


Validate inputs and sanity check derived values.


Return an appropriate exit code: zero for success and nonzero for failure.


Use appropriate naming conventions for variables, scripts, and routines.


User variable names that reflect the values they store.


Start every script with a comment block that tells what the script does and what parameters it takes. Include your name and the date. If the script requires non-standard tools, libraries, or modules to be installed, list those as well.


Comment at a useful level. More complexity requires more comments.


Error messages should:



  • Go to STDERR, not STDOUT.

  • Include the name of the program that’s issuing the error.

  • State the function of operation that failed.

  • If a system call fails, include the perror string.

  • Exit with a code other than 0.





Answered 2 days AfterJan 28, 2022

Answer To: Each student will write a Bash script which provides information to the user comparing the statuses...

Pawan answered on Jan 30 2022
119 Votes
Introduction
In this assignment we intend to get details of processes running on a linux machine. All the details are present in /proc folder of th
e machine. The /proc folder have folders by the process ID (PID) number for each of the process currently running on the system. In order to solve this assignment which I used “ps” command present in the linux system extensively. by running “man ps”, we get the details of the applications of “ps” command to get various details of processes running in the system
Process
In order to create options in the bash script we used the following syntax
This selects one of the function to execute from the bash script. If the passed argument does not match nay option then it simply prints the Help() for the bash script.
The help prints all the possible options present in the script. It is coded as given above. It simply echo each statement.
Display the two processes most nearly identical in terms of run-time, memory size, etc.
In order to print the run-time of a process, we can use the command
ps axo pid,etime
However this command prints the run-time for all the PIDs. In order to select close run time PID , we do the follwing
$(ps axo pid,etime | awk '{print $2}' | sed -n 2p | cut -c 1-5)
From left to right following is performed
· print pid and run-time
· select the second colum
· select 2nd value
· select the text written in first five cells
Now this value is used to get matching times form the PID list
ps axo...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here