Question 1 Write a shell script that takes a process name as input and checks if the process is running. If it's running, it should display the process ID; otherwise, it should display a message that the process is not running.
Added by Marina M.
Close
Step 1
This can be done using the `read` command in bash. Show more…
Show all steps
Your feedback will help us improve your experience
Akash M and 80 other AP CS educators are ready to help you.
Ask a new question
Labs
Want to see this concept in action?
Explore this concept interactively to see how it behaves as you change inputs.
Key Concepts
Recommended Videos
There are two (2) problems with this script. The first involves an error in the output about a missing command. The second is the fact that the vmstat command should include a timestamp for each line of output. To address the second problem, you will need to read the documentation for vmstat. #!/bin/bash date echo "uptime: $(uptime)" echo "Currently connected:" w echo "--------------------" echo "Last logins:" last -a | head -3 echo "--------------------" echo "Disk and memory usage:" df -h | xargs | awk '{print "Free/total disk: " $11 " / " $9}' free -m | xargs | awk '{print "Free/total memory: " $17 " / " $8 " MB"}' echo "--------------------" start_log=$(head -1 /var/log/syslog | cut -c 1-12) oom=$(grep -ci kill /var/log/syslog) echo -n "OOM errors since $start_log: $oom" echo "" echo "--------------------" echo "Utilization and most expensive processes:" top -b | head -3 top -b | head -10 | tail -4 echo "--------------------" echo "Open TCP ports:" nmap -p- -T4 127.0.0.1 echo "--------------------" echo "Current connections:" ss -s echo "--------------------" echo "Processes:" ps auxf --width=200 echo "--------------------" echo "vmstat:" vmstat 1 5
Akash M.
Write a script Prog1 that can be called with one parameter (the name of a directory) and displays the contents of that directory as output. Write a script Sum that can be called with two parameters (integers) and displays their sum on the screen. Write a script Prog2 that can be called with a parameter and displays on the screen whether it is a file, directory, or neither. Write a script Prog3 to concatenate two files, f1 and f2, into a file f3 and display the number of words in f3. (f1 and f2 must be created beforehand). Write a script Prog4 which: - Creates a directory called Rep. - Creates a file called liste1 in that directory, containing a detailed list of files and directories in the current directory. - Makes a copy of the file list1 with the name list2 in Rep. - Removes the file list1. Write a script Prog5 which: - Creates a directory with the name passed as a parameter in the current directory. - Copies a file with the name passed as a parameter into the created directory. Write a script Prog6 that: - Deletes all the files in a directory passed as a parameter. - Then deletes the directory itself.
In Linux, type the command that will display the list of jobs that bash is tracking for a particular session. 2. Type the command that will bring job #2 to the foreground. Once complete, use ctrl+z to suspend that job. 3. Type the command with the appropriate options that will display all processes, including processes without a controlling terminal. Make sure to show the sleep processes in your screenshot. 4. Type the command with the appropriate option to send a signal to one of the sleep PIDs to cause abrupt program termination that cannot be blocked, ignored, or handled.
Recommended Textbooks
Computer Science and Information Technology
Introduction to Programming Using Python
Computer Science - An Overview
Transcript
18,000,000+
Students on Numerade
Trusted by students at 8,000+ universities
Watch the video solution with this free unlock.
EMAIL
PASSWORD