LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
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, 07: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, 07:28 PM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,362

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
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



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 12:48 PM
kill command micro_xii Linux - Newbie 4 11-24-2006 08:48 AM
Kill command could not kill Kanaflloric Linux - General 11 08-22-2005 07:18 AM
The kill command tearinox Linux - Newbie 2 08-15-2003 04:40 PM
kill command... Sonny Linux - Newbie 2 01-28-2002 03:08 AM

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

All times are GMT -5. The time now is 10:50 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