Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

As you complete each of the following steps, keep track of what occurs at each p

ID: 3671154 • Letter: A

Question

As you complete each of the following steps, keep track of what occurs at each point, including what you type, the output given, and any errors experienced. Submit this information in a log to your instructor for this week’s assignment. Your log can use the sample format provided, or you can create your own. 1. In the same folder as last week, create a new file titled week4prog1[name].scr. 2. Change the permissions on this new file to add the execute bit for user, group, and owner. 3. Run the following script: a. #!/bin/bash b. count=1 c. echo "start of the program" d. while [ $count -le 10 ] e. do 1) echo "Loop #$count" 2) sleep 10 3) count=$[ count + 1 ] f. done g. echo "end of the program 4. Modify the program to add a trap for SIGINT and SIGTERM. 5. Save the script and then run the script in the background. 6. Use the jobs command to display a list of the jobs currently running. 7. Find the process id of the script and kill the job. 8. Check to see if you get the trap message. 9. Run the script again using the at command to schedule the job in the future. Wait for the job to run to make sure it executes.

Explanation / Answer

I have created the script and runned it without using SIGINT and SIGTERM, output is given below:

start of the program
Loop #1
Loop #2
Loop #3
Loop #4
Loop #5
Loop #6
Loop #7
Loop #8
Loop #9
Loop #10
end of the program

Script after adding trap for SIGINT

     1 #!/bin/bash
     2 count=1
     3 echo "start of the program"
     4 trap "echo ' interrupted me.' " SIGINT
     5 while [ $count -le 10 ]
     6 do
     7 echo "Loop #$count"
     8 sleep 10
     9 count=$[ count + 1 ]
    10 done
    11 echo "end of the program"

In the modified script we have used trap, now if we run the script and when the script is executing and we press "ctrl +c' then we get "interrupted me" message.

If script is in the current directory then you can run following given command to run the script in background

./script_name.sh > /dev/null 2>&1 &

now run commd

jobs -l

this above command will give you the script_process_id

then kill script_process_id to kill the process

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote