The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
.
google unix.com



High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
script to monitor process running on server and posting a mail if any process is dead pradeepmacha Shell Programming and Scripting 13 03-06-2009 07:33 AM
UID & GID of the running process ankurjain UNIX for Dummies Questions & Answers 2 01-09-2008 10:33 AM
How to create a dummy process of a process already running? shambhu UNIX for Advanced & Expert Users 3 08-31-2007 11:22 AM
launch & monitor process on remote host mrx Shell Programming and Scripting 1 10-15-2004 11:20 AM
Lightwight Process monitor LivinFree Shell Programming and Scripting 7 11-21-2001 05:56 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-14-2001
Pedro Tavares Pedro Tavares is offline
Registered User
  
 

Join Date: Nov 2001
Posts: 1
How to monitor if a process is running

I would like to know if i can monitor if a process is running.
I have one program wich is running all the time, called oliba, but sometimes it goes down, and I have to launch it again.
Is there a way to monitor the pid of the program, and if the program goes down, to lauch it again?
Can you give me an example of a source?

Thanks in advance.
  #2 (permalink)  
Old 11-14-2001
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,131
See this thread for a discussion about doing this from a shell. But the same technique works well in C, just invoke the kill system call using zero as the signal. Then check to see if it worked. Sample source code, huh? Well...

Code:
    if (kill(pid,0))

Sorry, I couldn't resist...
  #3 (permalink)  
Old 11-14-2001
PxT's Avatar
PxT PxT is offline Forum Advisor  
Registered User
  
 

Join Date: Oct 2000
Location: Sacramento, CA
Posts: 909
Use inittab, or <A HREF="http://cr.yp.to/daemontools.html">daemontools</A>
  #4 (permalink)  
Old 11-14-2001
nahaz nahaz is offline
Registered User
  
 

Join Date: Nov 2001
Posts: 2
While this response doesn't really belong in the C Programming section, the best way that I can see to ensure that your process runs all the time would be to write some sort of wrapper shell script to run the program with. Here is how you could do it in perl:

<hr noshade>
#!/usr/bin/perl

use strict;

my $OLIBA_CMD = '/[path to oliba here]/oliba';
my $SLEEP_TIME = 5; # check to see if it is running every 5 seconds

while(1)
{
my @pid_array = `ps -ef | grep [o]liba`; # thanks Perderabo

my $pid_count = scalar(@pid_array);

if ($pid_count == 0)
{
# uh oh it isn't running
system "$OLIBA_CMD"; # run it
}
elsif ($pid_count > 1)
{
# There is more than one instance running?
# code to mail the admin or something in here
}
sleep $SLEEP_TIME;
}
<hr noshade>

Hope this helps.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 11:31 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0