The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
how to check if a process is running in a server from shell script. debu UNIX for Advanced & Expert Users 2 01-24-2008 02:19 PM
check process running rose1207 Shell Programming and Scripting 4 12-27-2007 10:23 PM
script to check for a particular process and alert if its not running goks Shell Programming and Scripting 1 12-09-2005 02:11 AM
How to check if another instance of the process is running sim Shell Programming and Scripting 8 06-30-2005 04:24 AM
check my code?? running shell from c? abdul UNIX for Dummies Questions & Answers 1 09-03-2001 12:05 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 03-24-2006
agp agp is offline
Registered User
 

Join Date: Mar 2006
Posts: 1
How to check for specific process running through shell

Hi
I want to check whether specific process is running or not through a shell script.
ps -ef | grep will tell me this, i tried this way in shell

cnt =`ps -ef| grep xyz | awk '{ END {print NR}}`

if it return two rows, job is running else not.

Is there any better way of doing this.
Reply With Quote
Forum Sponsor
  #2  
Old 03-25-2006
blowtorch's Avatar
Supporter
 
Join Date: Dec 2004
Location: Singapore
Posts: 2,326
How about using grep twice over? If you wanted to check if inetd was running, you could use:
Code:
ps -ef | grep inetd | grep -vc grep
This will print out the number of running instances of the process that you are checking for.
Reply With Quote
  #3  
Old 03-25-2006
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,698
Why two rows ?
Try this

Code:
cnt=$(ps -ef | grep -c '[x]yz')
Reply With Quote
  #4  
Old 03-25-2006
blowtorch's Avatar
Supporter
 
Join Date: Dec 2004
Location: Singapore
Posts: 2,326
Quote:
Originally Posted by vino
Why two rows ?
Try this

Code:
cnt=$(ps -ef | grep -c '[x]yz')
I don't think that the OP means that s/he is searching for two processes. The output of a 'ps -ef |grep ...' often throws up the process for grep as well. So the count is two...
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 11:03 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0