LinuxQuestions.org
Register a domain and help support LQ
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 07-28-2011, 08:11 PM   #1
Chupakabra
LQ Newbie
 
Registered: Jul 2011
Posts: 12

Rep: Reputation: Disabled
using the kill command


I want to run a script. I want the script to run in the background. I want it to run for 5 seconds. Then I want to use the kill command to stop it.

would I use

sleep 5 in my script

and what kill command would I use in my script to stop it automaticaly.
 
Old 07-28-2011, 08:28 PM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
To background a cmd
Code:
/dir/prog &
# at this pt, $! holds the pid of the backgrounded job.
# recommend saving it
mypid=$!

sleep 5

kill $mypid
http://tldp.org/LDP/abs/html/internalvariables.html
 
  


Reply


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
why we cannot kill process id 1 with command "kill -9 1" satyaredhat Linux - Newbie 7 03-11-2009 01:48 PM
kill command micro_xii Linux - Newbie 4 11-24-2006 09:48 AM
Kill command could not kill Kanaflloric Linux - General 11 08-22-2005 08:18 AM
The kill command tearinox Linux - Newbie 2 08-15-2003 05:40 PM
kill command... Sonny Linux - Newbie 2 01-28-2002 04:08 AM


All times are GMT -5. The time now is 07:06 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration