LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to kill a script ? (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-kill-a-script-787637/)

manimin2 02-07-2010 04:26 PM

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 ??

devnull10 02-07-2010 04:31 PM

ctrl+c works fine for me.

Samotnik 02-07-2010 04:38 PM

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).

chrism01 02-07-2010 05:41 PM

The clue is in the qn
Quote:

The script is to be run in the background.
You're just sending the sleep into the the background... Think about the requirement more closely.

manimin2 02-07-2010 05:53 PM

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.

chrism01 02-07-2010 06:07 PM

I'm trying not to just give you the answer, but
Code:

sleep 1 &
j=1


wait

1 of those lines needs changing, 2 need removing.
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.