LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 02-25-2005, 02:29 AM   #1
chrisfirestar
Member
 
Registered: Sep 2003
Location: Adelaide, Australia
Distribution: Fedora/RH
Posts: 231

Rep: Reputation: 30
checking if service is running and if so kill it


Hi everyone,

I am wanting to do the following:

check if a process is running, if it is then we kill it.

I have been able to get the PID of the process which is now known as

$PID

but i need to now using:

ps -ef | grep $PID | grep -v grep

I can list the item but then how do I go about checking etc.

something like

$CHECK=`$ps -ef | $grep $PID | $grep -v grep`

if [ $CHECK == "" ]
echo "Service has shutdown correctly"
fi
echo "Service did not shut down correctly"
echo "Killing service"
kill -9 $PID

it is the if [ blah blah ] that I am unclear on.

Thanks
 
Old 02-25-2005, 02:50 AM   #2
chrisfirestar
Member
 
Registered: Sep 2003
Location: Adelaide, Australia
Distribution: Fedora/RH
Posts: 231

Original Poster
Rep: Reputation: 30
got it already haha sorry to waste your times...

pid=213 # example only :P
CHECK=`$ps -ef | $grep $pid | $grep -v grep`

if [ "$CHECK" ]
then
echo Service did not shut down correctly... forcing shutdown
kill -9 $pid
exit 0
fi
echo Service Appears to have shutdown
 
Old 02-25-2005, 03:17 AM   #3
hiteshmaisheri
Member
 
Registered: Nov 2003
Location: Kerala, India
Distribution: Red Hat, Knoppix, Mandrake, FreeBSD
Posts: 231

Rep: Reputation: 30
Hii,
i did not get through the idea behind the code .. can u please clarify...

Hitesh
 
Old 02-25-2005, 03:23 AM   #4
chrisfirestar
Member
 
Registered: Sep 2003
Location: Adelaide, Australia
Distribution: Fedora/RH
Posts: 231

Original Poster
Rep: Reputation: 30
basically i have the PID of a service running. I run a stop script however sometimes the stop fails. then when my service tries to start up again it complains because it cant bind to the port.

so what i do is ps for the PID... if it exists then i kill it.
 
  


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
Checking for X.....no ??? I'm running Kde!! fatrandy13 Linux - Software 5 06-01-2005 03:57 PM
Checking to See if MySQL is Running HappyDude Linux - Software 3 12-10-2004 06:52 PM
Checking Speedtouch 330 ADSL modem is working before service is provided? Proud Linux - Networking 6 08-11-2004 02:30 PM
Checking what resolution X is running at pwaring Linux - Software 2 06-05-2004 02:36 PM
Checking Running Services Chijtska General 3 03-13-2002 11:12 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 02:33 PM.

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