How to tell if a process is running?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to tell if a process is running?
# 22  
Old 11-06-2011
Thought I had better report back on this.

Success!!!

Code:
#!/bin/sh
 
#checking to see if fmxdbc_listener exists and writing to a variable

ps -ax |grep '/fmxdbc_listen' |grep -v grep > /dev/null 2>&1

#echo "$checkfmxdbc"

if [ $? = "0" ]; then
	echo "fmxdbc_listener is still Running - `date`" >>  /checkfmxdbc.log
else
	echo "ERROR - fmxdbc_listener is NOT Running - `date`" >>  /checkfmxdbc.log
	cd /Applications/FileMaker\ Pro\ 11\ Advanced/Extensions/xDBC\ Support/fmxdbc_listener.bundle/Contents/MacOS/
	./fmxdbc_listener -u &
fi

Works as expected. Zombie processes be damned!

Thank you to all those that helped.
# 23  
Old 11-06-2011
You can avoid 'grep -v grep' by using grep '/[f]mxdbc_listen' instead. The [ ] don't change the meaning of the expression when put around one character, but prevent grep from matching itself.
# 24  
Old 11-06-2011
Cheers.

But is my new line:

Code:
ps -ax |grep '/[f]mxdbc_listen' | > /dev/null 2>&1

or
Code:
ps -ax |grep '/[f]mxdbc_listen' |grep > /dev/null 2>&1

or something else.

< newb
# 25  
Old 11-07-2011
Code:
ps -ax |grep '/[f]mxdbc_listen' > /dev/null 2>&1

Incidentally, some versions of ps (e.g. GNU) have a -C option that let you search by command, e.g.
Code:
ps -C fmxdbc_listener

# 26  
Old 11-07-2011
Cheers Corona. I love how with Unix no matter how long and convoluted the command there is always a shorter, pithier way of expressing the same thing, that just depends on your knowledge level (or access to resources such as this forum). Smilie

---------- Post updated at 10:08 AM ---------- Previous update was at 10:05 AM ----------

Quote:
Originally Posted by CarloM
Code:
ps -ax |grep '/[f]mxdbc_listen' > /dev/null 2>&1

Incidentally, some versions of ps (e.g. GNU) have a -C option that let you search by command, e.g.
Code:
ps -C fmxdbc_listener

Cheers Carlo. Works fine.

Tried -C and it is an illegal argument is this particular flavour of unix.
# 27  
Old 11-22-2011
Hey guys, thanks for all your help. I just need to ask one more question.

The script works and detects whether or not fmxdbc_listener is running, ECHOs the results to the log, and if negative, fires up fmxdbc_listener. But it doesn't work when fired up by launchd (I take it this is the new 'cron').

I'm guessing it has to do with the account permissions that launchd fires it up with.

Code:
./fmxdbc_listener -u &

I believe the -u means start it with the current user, which is correct when I trigger it manually but I'm guessing not so when launchd fires it off.
# 28  
Old 11-23-2011
i sometimes check if the process has a log file. if so, then check if it's being populated.
if log file is being populated, then you'll know the answer.

cheers!
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Command to get exact tomcat process I am running ignoring other java process

Team, I have multiple batchjobs running in VM, if I do ps -ef |grep java or tomcat I am getting multiple process list. How do I get my exact tomcat process running and that is unique? via shell script? (4 Replies)
Discussion started by: Ghanshyam Ratho
4 Replies

2. UNIX for Advanced & Expert Users

Process remians in Running state causing other similar process to sleep and results to system hang

Hi Experts, I am facing one problem here which is one process always stuck in running state which causes the other similar process to sleep state . This causes my system in hanged state. On doing cat /proc/<pid>wchan showing the "__init_begin" in the output. Can you please help me here... (6 Replies)
Discussion started by: naveeng
6 Replies

3. UNIX for Advanced & Expert Users

Process remians in Running state causing other similar process to sleep and results to system hang

Hi Experts, I am facing one problem here which is one process always stuck in running state which causes the other similar process to sleep state . This causes my system in hanged state. On doing cat /proc/<pid>wchan showing the "__init_begin" in the output. Can you please help me here... (1 Reply)
Discussion started by: naveeng
1 Replies

4. BSD

Process remians in Running state causing other similar process to sleep and results to system hang

Hi Experts, I am facing one problem here which is one process always stuck in running state which causes the other similar process to sleep state . This causes my system in hanged state. On doing cat /proc/<pid>wchan showing the "__init_begin" in the output. Can you please help me here... (0 Replies)
Discussion started by: naveeng
0 Replies

5. UNIX for Dummies Questions & Answers

Need help in running a process

Hello All, We are running a process in unix box. This is how we will do 1.our process name is Runprojectprocess <ID> configuration 2.We will be running upto 500 id at once. So we are populating a text file as Runprojectprocess 1 configuration to Runprojectprocess 500 configuration 3.... (2 Replies)
Discussion started by: arunkumar_mca
2 Replies

6. UNIX for Dummies Questions & Answers

How a process can check if a particular process is running on different machine?

I have process1 running on one machine and generating some log file. Now another process which can be launched on any machine wants to know if process1 is running or not and also in case it is running it wants to stream the logs file generated by process1 on terminal from which process2 is... (2 Replies)
Discussion started by: saurabhnsit2001
2 Replies

7. UNIX for Dummies Questions & Answers

Running different process from current process?

I have been having some trouble trying to get some code working, so I was wondering...what system calls are required to execute a different program from an already running process? (1 Reply)
Discussion started by: Midwest Product
1 Replies

8. UNIX for Advanced & Expert Users

How to know process is running or not?

please suggest me a way to write c program that takes pattern of the process and returns true or false my case is i need to keep track of dhcpcd dhcpcd -d eth1 so i tried popen("ps -ef | grep dhcpcd | grep eth1 | wc -l", "r"); but pipe is storing 1 or 2 when not running and 2 or 3... (7 Replies)
Discussion started by: Gopi Krishna P
7 Replies

9. Shell Programming and Scripting

script to monitor process running on server and posting a mail if any process is dead

Hello all, I would be happy if any one could help me with a shell script that would determine all the processes running on a Unix server and post a mail if any of the process is not running or aborted. Thanks in advance Regards, pradeep kulkarni. :mad: (13 Replies)
Discussion started by: pradeepmacha
13 Replies

10. UNIX for Advanced & Expert Users

How to create a dummy process of a process already running?

Hi Everybody, I want to create a shell script named as say "jip" and it is runned. And i want that when i do ps + grep for the process than this jip should be shown as process. Infact there might be process with name jip which is already running. (3 Replies)
Discussion started by: shambhu
3 Replies
Login or Register to Ask a Question