I am very new to shell scripting.I have the requirement like
one program is there, if it is running leave like that only and if it is stopped it has to be restart and once again keep watching and it is stopped we a have to restart once agian.I want a shell script for this.Please help me in this.
What distribution or operating system are you referring to? In linux the init.d files do exactly this by writing out PID files to see if the program is still alive when it re-executes.
Please provide more information.
Hi i am working on unix environment.I have the requirement like.
If i have a program.c and it is running.Different signals comes into picture.Like below
The program may be like
The signals are,
case SIGHUP: return "JVM hangup";
case SIGINT: return "JVM interrupted";
case SIGQUIT: return "JVM Quit";
case SIGILL: return "Illegal instruction";
case SIGABRT: return "JVM aborted";
case SIGFPE: return "Floating point exception";
case SIGKILL: return "JVM killed";
case SIGBUS: return "Bus error";
case SIGSEGV: return "Segmentation violation";
case SIGSYS: return "Bad argument to system call";
case SIGTERM: return "Software termination signal from kill";
case SIGCHLD: return "Child process terminated or stopped";
default: return "JVM abnormally terminated";
If the above signals comes also the program has to run.
This is what I required.But i dont know how to code these signlas to trap.
I think I am clear from my end.If you didnt get my requirement please let me know.
Thank you very much for your valuable reply.But i have some doubt.
what is pidfile.Where it is created.I am new to unix please clarify my doubt.
if [ -e $pidfile ]; then
if kill -0 &>1 > /dev/null $pid; then
echo "Already running"
echo $$ > $pidfile
#do your thing here
When you create a process it is assigned a 'process id' or PID. In the PID file you write out the process ID .. that way you can see if that process is still running so you dont start up a new instance every time. you can change the location of the pid file by changing the pidfile= line