LinuxQuestions.org
Help answer threads with 0 replies.
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 01-31-2008, 12:51 PM   #1
Azk00
LQ Newbie
 
Registered: Jan 2008
Location: Madrid, Spain
Distribution: OpenSuse
Posts: 2

Rep: Reputation: 0
How to stop a process running in background (on a shell script)


Hi, this is my first approach to shell scripts and Iím a bit lost .

I have a server-client app, and I want to run a server with a pair of clients. So I run this 3 processes in background, but when I need to stop them, I donít know how. Is there any equivalent to Ctrl-C with shell scripts?

Iíve been searching on bash man for something like getting its pid and later killing them, but couldnít find how. Any suggestion?

And another silly question is How can I make my shell wait for N seconds before running next command?
I need the second client to start about 20 secs after the 1st one has connected so Iíve solved this by repeating a few ďlsĒ between them but its ridiculous and Iím sure there has to be another way.

To give you an idea of how newbie I am, hereís my script:

Code:
#!/bin/bash
set Ėx

cd server
./run > servertrc.txt &

ls
ls
[..]
ls

cd ../client1
./run &

ls
ls
[..]
ls

cd ../client2
./run &

exit 0
Thanks for any help or hint!
 
Old 01-31-2008, 01:14 PM   #2
jailbait
Guru
 
Registered: Feb 2003
Location: Blue Ridge Mountain
Distribution: Debian Wheezy, Debian Jessie
Posts: 7,578

Rep: Reputation: 187Reputation: 187
Quote:
Originally Posted by Azk00 View Post

Iíve been searching on bash man for something like getting its pid and later killing them, but couldnít find how. Any suggestion?
You can find the PIDs of all running processes with the top command. See:

man top


Quote:
Originally Posted by Azk00 View Post

I need the second client to start about 20 secs after the 1st one has connected so Iíve solved this by repeating a few ďlsĒ between them but its ridiculous and Iím sure there has to be another way.
Use the sleep command. See:

man sleep

----------------------
Steve Stites
 
Old 01-31-2008, 01:35 PM   #3
dive
Senior Member
 
Registered: Aug 2003
Location: UK
Distribution: Slackware
Posts: 3,211

Rep: Reputation: 293Reputation: 293Reputation: 293
You can find the pid with pgrep. Kill the running program or script with kill. Or combine the two:

kill `pgrep <programname>`
 
Old 02-01-2008, 05:24 AM   #4
Azk00
LQ Newbie
 
Registered: Jan 2008
Location: Madrid, Spain
Distribution: OpenSuse
Posts: 2

Original Poster
Rep: Reputation: 0
Done, thanks to Steve Stites and dive for spending their time on answering .
I finally stopped the process with
Code:
pkill -x <programname>
and seems to work ok.
 
  


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
shell script switching it self into background process knockout_artist Linux - Software 3 11-24-2007 12:33 PM
Stop process while running script azazel11998 Programming 1 07-01-2007 05:12 AM
running process in background forever danran Linux - General 2 11-19-2006 10:44 AM
Running kismet as a background process coolnicklas Linux - Software 2 01-04-2006 04:33 PM
background running process elbriga Programming 2 09-21-2004 07:08 PM


All times are GMT -5. The time now is 05:58 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration