LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-07-2010, 04:26 PM   #1
manimin2
LQ Newbie
 
Registered: Feb 2010
Posts: 2

Rep: Reputation: 0
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 ??
 
Old 02-07-2010, 04:31 PM   #2
devnull10
Member
 
Registered: Jan 2010
Location: Lancashire
Distribution: Slackware Stable
Posts: 572

Rep: Reputation: 120Reputation: 120
ctrl+c works fine for me.
 
Old 02-07-2010, 04:38 PM   #3
Samotnik
Member
 
Registered: Jun 2006
Location: Belarus
Distribution: Debian GNU/Linux testing/unstable
Posts: 471

Rep: Reputation: 40
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).
 
Old 02-07-2010, 05:41 PM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,308

Rep: Reputation: 2744Reputation: 2744Reputation: 2744Reputation: 2744Reputation: 2744Reputation: 2744Reputation: 2744Reputation: 2744Reputation: 2744Reputation: 2744Reputation: 2744
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.
 
Old 02-07-2010, 05:53 PM   #5
manimin2
LQ Newbie
 
Registered: Feb 2010
Posts: 2

Original Poster
Rep: Reputation: 0
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.
 
Old 02-07-2010, 06:07 PM   #6
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,308

Rep: Reputation: 2744Reputation: 2744Reputation: 2744Reputation: 2744Reputation: 2744Reputation: 2744Reputation: 2744Reputation: 2744Reputation: 2744Reputation: 2744Reputation: 2744
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/
 
  


Reply

Tags
kill, script


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Script to kill process id farooqkadri Red Hat 13 10-01-2009 11:54 AM
need grep script to kill process Cyberman Programming 4 08-31-2009 10:51 AM
kill the process invoked from a shell script, when the script is killed kskkumar Linux - Software 8 05-23-2007 11:29 AM
kill process script adnanm Linux - Newbie 3 03-02-2007 12:30 PM
script to kill processes tradnbillies Linux - Software 2 04-28-2006 03:00 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:28 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration