HW5 - solution

docx

School

Santa Clara University *

*We aren’t endorsed by this school

Course

107

Subject

Computer Science

Date

Feb 20, 2024

Type

docx

Pages

2

Uploaded by derleen101

Report
Assignment 5 Instructions: Write the commands needed to solve the following exercises on mis01.scu.edu. Problem 1 (1 point) Find the number of existing processes. Your output should be formatted as follows: On xxx, there were yyy processes xxx is the current timestamp (which you can retrieve with the command date ) yyy is the number of processes For example: On Thu Oct 20 12:33:31 PDT 2022, there were 305 processes Solution ps -efl | awk '{if (NR>1) print $0}' | wc -l Problem 2 (1 point) The file /home/OMIS107/HW5/name contains one line of text. How much RAM is used in total by processes whose names contain that text? Your code should return just a number from 0 to 100 . For instance, if /home/OMIS107/HW5/name contains the text ps , then your code should total the % of RAM of any process that contain "ps" in the COMMAND column, and return the result (a number from 0 to 100). Your code must work correctly even if the content of /home/OMIS107/HW5/name is changed. Solution ps aux | awk -v n="$(cat name)" 'BEGIN{sum=0} {if ($11 ~ n) {print $0;sum+=$4}} END{print sum}' Problem 3 (1 point) Position yourself in /home . Print only the file/directory name , followed by a colon, followed by the “group” permissions (the middle three permission bits) for all of the files/directory owned by the current user (whomever the user may be). Example: the output of the command executed by msamorani is this: Solution ls -l | awk -v u="$(whoami)" '{if ($3==u) print $9 ":" $1}' | sed -r "s/: .... (...).*/:\1/g"
Problem 4 (1 point) Read file hw5 inside your directory. Create one problem (text + solution ) as indicated in that file and then upload your problem and solution on this shared document . The goal is to help fellow students to prepare for the midterm; so, try to make the problem useful. The text of your problem should be as clear as possible and as short as possible. Avoid creating problems that are too trivial or too difficult; the difficulty of your problem should be similar to the problems in this and past assignments. My intention is to give everyone full marks; the only way not to get full marks are the following: You do not perform this task You do not include a solution Your problem is clearly too trivial. For example, “print the current date” (solution: date ), “print the list of existing processes” (solution: ps -efl ). If the solution you provide is incorrect, you will still receive full marks. But you must make an honest effort to get it right.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help