How to kill a script ?
Hi all,
I know that i cant ask questions from my assignment. But i am stuck at one point. Following is my assignment question. Write a shell script which will count down (i.e. display) from 10 to 1, display "bang", and repeat endlessly. There will be a 1 second delay between the display of each count. The script is to be run in the background. I have made the script and its working fine. But the main problem is that i dont know how to kill that script. My professor needs a demonstration from me and wants to see how i am killing the script. Ctrl^z and Ctrl^c are not working. Here is my script: #!/bin/bash while (j=1) do for (( i=10; i>0; i--)); do sleep 1 & j=1 printf " $i \n" wait done done Could you please help me in this ?? |
ctrl+c works fine for me.
|
Every time you start a background process, it's assigned with a job specification (jobspec). You can kill then this process with kill %jobspec command (man bash).
|
The clue is in the qn
Quote:
|
Thanks for the quick reply. But my problem is that i dont have time to type kill %jobspec. Whenever i run my script in background in never ends because of the requirement.
But i am running the script like this $ ./count.sh & where count.sh is name of my script. |
I'm trying not to just give you the answer, but
Code:
sleep 1 & If you're sending the whole script into the background (as reqd) the you've got all the time in the world to figure out the correct kill cmd. Its an infinite loop (as reqd). http://rute.2038bug.com/index.html.gz http://tldp.org/LDP/Bash-Beginners-G...tml/index.html http://www.tldp.org/LDP/abs/html/ |
All times are GMT -5. The time now is 04:39 PM. |