start a unix process if its no longer running

I have a process running on a unix machine (AIX) which stops or dies every 30 minutes or so
I need a shell script to keep monitoring the process and start it if the process is no longer running

the process is started using /opt/abc/bin/skc
process name is skc

Who is Participating?
skullnobrainsConnect With a Mentor Commented:
if the above don't fit your needs, cron this

* * * * * pgrep skc || flock -w 60 /tmp/skc.lock /opt/abc/bin/skc

if you start it using cron, you can skip the "pgrep skc ||" part

this will restart the script instantaneously when it dies after having been restarted through cron but restart it at moast once per minute. you can change the numbers how you need

the init way seems better if available
Predefined RMC Conditions Installed by Default

At install time, more than 80 different conditions are defined within RMC and are for use with the click of a mouse (or command-line interaction). In addition to the conditions, predefined responses are provided with the system to support general-purpose activities such as e-mailing root, broadcasting an event and so on. Of course, to do something more useful requires writing specific response scripts that perform the actions needed to recover from the trigger conditions. For example:

The file system grows too large--increase the file system size or archive the data.
A process stops running--recover the process or restart the application.
Service levels start to drop--modify the Workload Manager (WLM) configuration or perform a dynamic LPAR (DLPAR) operation.
A server fails--execute recovery and move the workload to a different server.

Do you have RMC available on your environment?  That would be the simple and AIX way to do things.
Add the process to inittab file with the respawn option.

Check the man pages for inittab for the exact syntax.
Ernie GronblomCloud Systems EngineerCommented:
Fortunately there is a program that comes with every Unix system that does just that!  It is the init process and it will monitor any process it starts and can restart it if it should go away.

Add the following line to your /etc/inittab file:

Then, run 'init q' to have it start the process (make sure it isn't already running) or you can reboot your system and the process will start as soon as the run level gets to 2, 3, or 4.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.