keeping a process alive ?


 
Thread Tools Search this Thread
Operating Systems Solaris keeping a process alive ?
# 1  
Old 11-24-2010
keeping a process alive ?

Hello guys, I have one script running that I need to keep it running 24x7 so I'd like to know how can I implement a sort of monitoring process I mean if for some reason this process dies somehow it gets automatically started again.

Thanks.
# 2  
Old 11-24-2010
You can create SMF service for that script. Then the SMF itself will monitor availability of that script, and will restart it if needed. Take a look at: BigAdmin Feature Article: Using Service Management Facility (SMF) in the Solaris 10 OS: A Quick Example
# 3  
Old 11-24-2010
thanks for answering, I took a look at it and it sounds a lot complex, there is no simpler way ?

Thanks once again.
# 4  
Old 11-24-2010
Yes. use crontab to schedule a 'check_it_is_running' script every x minutes. The check it script will restart the other script if it is no longer running.

Every 5 minutes
Code:
5 * * * * /path/to/myscript/check.sh 2&>1 >> /path/to/logs/check.log

Note: your script has to recreate your environment fully by sourcing /etc/profile and .profile
for the user. Bartus solution is definitely preferred.
# 5  
Old 11-24-2010
Try this ....

In order to know, if a process is running or gone, I can suggest you two methods:
1) Use pidof <name of your program> and check its return value which should be any number as the pid of your process but should not be zero. So if you get zero as return value, means the process is gone.

2) You may use ls /proc/<pid_of_your_process> should be sucessful. Meaning check the value of $? immediately and the decide, if your process is running or gone.

Now write a parent script which loops for ever (like while (1) ...) and checks the process state everytime, if your process is found to be not running then invoke the process again and sleep for a reasonable time to allow the process up and running before your this parent script loops to check the status of your process for the next time.

Also invoke your process, from this parent script, using nohup <your_process_name> &, as you would be knowing to allow your process run in the background and asynchronously to this script.

Cheers!!!!!!!!!!!! Smilie
# 6  
Old 11-24-2010
man inittab

This is exactly what it's for. Why reinvent it?
# 7  
Old 11-25-2010
Inittab is not really designed for non system applications. It also lacks most SMF features which is the way to go for Solaris 10 and newer.
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Programming

Socket Keep-Alive

Hi I'm adding http 1.1 GET to my project and trying to use “Keep-Alive” HTTP connections to the host, The problem is when I recv() the first page, it succeeds. However, the 2nd consecutive recv() will receive zero bytes, for which I really have no idea. As per HTTP 1.1 I have Connection: ... (6 Replies)
Discussion started by: Projecteer
6 Replies

2. What is on Your Mind?

Is this forum alive?

Odd thing. I posted in the Solaris forum, new user, just asking for a bit of advice. Nothing too complicated. As of this post there have been 140 views and zero replies. So that got me thinking, is this normal? I had a look around, and I see the same thing on many other threads, and in other... (2 Replies)
Discussion started by: _JonB_
2 Replies

3. Tips and Tutorials

My "Bread and Butter" Process Keep Alive Perl Script....

For the newbies, I should have posted this years ago.... Here is the standard (tiny) "bread and butter" perl script (on Linux) I use in my crontab files to insure key processes are alive ( just in case ! ) like httpd, named, sshd, etc. The example below if for named...... ... (1 Reply)
Discussion started by: Neo
1 Replies

4. Shell Programming and Scripting

Keeping std & err outputs alive and feed one log file in a one-shot way

Bonjour, I have a large script with a lot of print statements and misc commands. Standard and error outputs are redirected like into the following code : #!/usr/bin/ksh LOG=/<some dir>/log > $LOG exec >>${LOG} 2>>${LOG} print aaaaa print bbbbb print ccccc ... some_cmd That way,... (5 Replies)
Discussion started by: Fundix
5 Replies

5. Shell Programming and Scripting

keeping 10 process running at the same time

Hi guys, I neet to run sqlldr to charge about 50,000 files every day to my DWH, so I need to make an script to keep about 100 processes of sqlldr running at the same time. So, the issue is that i've been trying for a few days to make an script which can keep that amount of processes running, so... (2 Replies)
Discussion started by: razziel
2 Replies

6. UNIX for Dummies Questions & Answers

Check whether a process is alive or not

Hi Everybody I have small requirement that needs to be implemented in shell script. Currently i have shell script which invokes a java process say "Process A" which runs in background. If some one tries to invoke again the same shell script , then there should be some mechanism inside the... (23 Replies)
Discussion started by: appleforme1415
23 Replies

7. UNIX for Dummies Questions & Answers

Keeping cron jobs alive...?

Hi, I'm very new to Unix so please bear with me... :) Here is my requirement: I need to create a cron job to run two different scripts at 1 a.m. every day. Here's what I did: I used the "crontab -e" command and created a crontab file using the vi editor. When I exit the editor using... (3 Replies)
Discussion started by: yogiB
3 Replies

8. UNIX for Dummies Questions & Answers

how to kill process while keeping the submitted job running

:confused: I have a process which was schedule to run from 8am - 6pm daily. The scripts will search & run the commands that i was predefined in the database. Ususally, there were about 6-7 jobs for each submission and each job takes about 1-2 hrs and running one by one. And, I have a cron job... (3 Replies)
Discussion started by: hk_newbie
3 Replies
Login or Register to Ask a Question