0 Replies - 333 Views - Last Post: 19 December 2013 - 08:04 PM Rate Topic: -----

#1 TheCrownedPixel  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 16-December 13

trapping - ksh

Posted 19 December 2013 - 08:04 PM

Been working at this fora while now.

I understand the concept, just missing the preciseness on how to complete the code.

The task is as follows:


The script will be executed in the foreground. This script should write out a message “USR signal was handled” whenever a USR1 or USR2 signal is sent to it. You should also keep track of the number of USR1 and the number of USR2 signals that are processed by the script. When an INT signal is received by the script, a trap handler should write out the number of USR1 and the number of USR2 signals that have been received. Finally, in response to the INT signal, the INT trap handler should exit the script with a status code of 2.
The body of the script should be a loop that executes 100 times. Inside the loop, the script executes sleep 1 . If no INT signal is received then the script should write the message “exiting normally” and return a status code of zero.
To test out your script, you should use two windows, each of which is connected to the sol computer. In the first window, execute your ksh script. In the second window, find out the pid (e.g. 1234) of the script that is running and then you can send it signals via the kill command. For example,
kill – USR1 1234 kill – USR2 1234 kill – USR2 1234 kill – INT 1234

Here is what I have so far:


trap sig1 USR1
trap sig2 USR2
trap exithandler TERM INT

sig1() {
    num1 = $((num1+1))
    echo "USR signal was handled"

sig2() {
    num2 = $((num2+1))
    echo "USR signal was handled"

exithandler() {
    echo "Recieved an INT, exiting."
    exit 2

seconds = 0
count = 0
while [[$count -lt 100]] do
    sleep 1
    echo $count
    count = $((count+1))

Is This A Good Question/Topic? 0
  • +

Page 1 of 1