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
 
LinkBack Search this Thread
Old 01-31-2008, 11:51 AM   #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, 12:14 PM   #2
jailbait
Guru
 
Registered: Feb 2003
Location: Blue Ridge Mountain
Distribution: Debian Squeeze, Fedora 14
Posts: 7,268

Rep: Reputation: 86
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, 12:35 PM   #3
dive
Senior Member
 
Registered: Aug 2003
Location: UK
Distribution: Slackware
Posts: 3,081

Rep: Reputation: 231Reputation: 231Reputation: 231
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, 04: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
Trackbacks are Off
Pingbacks are On
Refbacks are 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 11:33 AM
Stop process while running script azazel11998 Programming 1 07-01-2007 04:12 AM
running process in background forever danran Linux - General 2 11-19-2006 09:44 AM
Running kismet as a background process coolnicklas Linux - Software 2 01-04-2006 03:33 PM
background running process elbriga Programming 2 09-21-2004 06:08 PM


All times are GMT -5. The time now is 05:30 PM.

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
Open Source Consulting | Domain Registration