LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-27-2007, 07:26 AM   #1
sharathkv25
Member
 
Registered: Jul 2006
Distribution: HP-UX
Posts: 46

Rep: Reputation: 15
find if program is running


Hi,


I want to find if a particular program is running. The program name is tpsnmp. It is not running at the moment. I have similar named programs that are running.

ps -ef gives me this result:

#ps -ef | grep tpsnmp
root 25795 1 0 Jun 25 ? 0:00 /opt/osmf/SNMP/bin/tpsnmpmad
root 25796 1 0 Jun 25 ? 0:00 /opt/osmf/SNMP/bin/tpsnmpd


In this case I should be no output. How to make this possible?

Thanks
 
Old 06-27-2007, 07:30 AM   #2
b0uncer
LQ Guru
 
Registered: Aug 2003
Distribution: CentOS, OS X
Posts: 5,131

Rep: Reputation: Disabled
Code:
ps -ef | grep tpsnmp$
Does that work better? Sorry I have no Linux/Unix around so can't test, but I recall that dollar sign meant "line ends with this". If it's not enough, you can use cut, sed or awk and grep's ^ before the string which means "line starts with this", or combine those.
 
Old 06-27-2007, 07:37 AM   #3
nx5000
Senior Member
 
Registered: Sep 2005
Location: Out
Posts: 3,307

Rep: Reputation: 57
Code:
 pgrep -x tpsnmp &> /dev/null && echo "running" || echo "not running"
Depending on the OS, there is also pidof
 
Old 06-27-2007, 07:40 AM   #4
Hobbletoe
Member
 
Registered: Sep 2004
Location: Dayton, Oh
Distribution: Linux Mint 17
Posts: 150

Rep: Reputation: 18
Actually, for a regular expression, you may need to use 'grep -e', or egrep. Put your regular expression in quotes.

Code:
ps -ef | egrep 'tpsnmp$'
I think you could also use the -w option for grep here which means that the string must be the beginning of the line or a non-word character, or that it must be at the end of the line or followed by a non-word character or both.

Code:
ps -ef | grep -w tpsnmp
You might also want to exclude grep from your returns to make the output a bit clearer.

Code:
ps -ef | grep -v grep | grep -w tpsnmp
 
Old 06-27-2007, 01:28 PM   #5
dive
Senior Member
 
Registered: Aug 2003
Location: UK
Distribution: Slackware
Posts: 3,467

Rep: Reputation: Disabled
Try 'pgrep tpsnmp'
 
Old 06-29-2007, 04:49 AM   #6
nx5000
Senior Member
 
Registered: Sep 2005
Location: Out
Posts: 3,307

Rep: Reputation: 57
Quote:
Originally Posted by dive
Try 'pgrep tpsnmp'
pgrep -x tpsnmp
 
  


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
can't find my program boncrs Linux - Desktop 10 04-21-2007 03:59 PM
cant find program Circuit Monkey Linux - Newbie 3 03-25-2005 04:36 AM
couldn't find program .....my ar$e munkie_poo Mandriva 3 05-24-2004 01:41 PM
How do I find out if another program is still running? nefch Programming 12 02-18-2004 09:41 AM
Running a C program isaacais Linux - Newbie 3 12-11-2002 02:22 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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