943,724 Members | Top Members by Rank

Ad:
Aug 4th, 2009
0

hi all please help me in this issue.

Expand Post »
Hi all,
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.

This is an urgent one.Thanks in advance.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
bhas85 is offline Offline
4 posts
since Aug 2009
Aug 6th, 2009
0

Re: hi all please help me in this issue.

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.
Featured Poster
Reputation Points: 1749
Solved Threads: 735
Senior Poster
sknake is offline Offline
3,948 posts
since Feb 2009
Aug 6th, 2009
0

Re: hi all please help me in this issue.

Click to Expand / Collapse  Quote originally posted by sknake ...
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
Shell Scripting Syntax (Toggle Plain Text)
  1. #include <stdio.h>
  2.  
  3. int main()
  4. {
  5. printf("Message 1\n");
  6. sleep(10);
  7. }

The signals are,
Shell Scripting Syntax (Toggle Plain Text)
  1. switch(signum){
  2. case SIGHUP: return "JVM hangup";
  3. break;
  4. case SIGINT: return "JVM interrupted";
  5. break;
  6. case SIGQUIT: return "JVM Quit";
  7. break;
  8. case SIGILL: return "Illegal instruction";
  9. break;
  10. case SIGABRT: return "JVM aborted";
  11. break;
  12. case SIGFPE: return "Floating point exception";
  13. break;
  14. case SIGKILL: return "JVM killed";
  15. break;
  16. case SIGBUS: return "Bus error";
  17. break;
  18. case SIGSEGV: return "Segmentation violation";
  19. break;
  20. case SIGSYS: return "Bad argument to system call";
  21. break;
  22. case SIGTERM: return "Software termination signal from kill";
  23. break;
  24. case SIGCHLD: return "Child process terminated or stopped";
  25. break;
  26. default: return "JVM abnormally terminated";
  27. break;
  28. }
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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
bhas85 is offline Offline
4 posts
since Aug 2009
Aug 6th, 2009
0

Re: hi all please help me in this issue.

If you start a new instance of the program then it won't signal the existing version.

Here are some pid file examples:
http://candrews.integralblue.com/200...-file-in-bash/
http://www.franzone.com/2007/09/23/h...ready-running/
http://ubuntuforums.org/archive/index.php/t-530553.html
Featured Poster
Reputation Points: 1749
Solved Threads: 735
Senior Poster
sknake is offline Offline
3,948 posts
since Feb 2009
Aug 6th, 2009
0

Re: hi all please help me in this issue.

i,
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.
Shell Scripting Syntax (Toggle Plain Text)
  1. #!/bin/bash
  2. pidfile=/var/run/sync.pid
  3. PROGRAM="/home/test/vijay/vijay1"
  4. $PROGRAM
  5. if [ -e $pidfile ]; then
  6. pid=`cat $pidfile`
  7. if kill -0 &>1 > /dev/null $pid; then
  8. echo "Already running"
  9. exit 1
  10. else
  11. rm $pidfile
  12. fi
  13. fi
  14. echo $$ > $pidfile
  15.  
  16. #do your thing here
  17.  
  18. rm $pidfile

Thanks,
Vijay,
Reputation Points: 10
Solved Threads: 0
Newbie Poster
bhas85 is offline Offline
4 posts
since Aug 2009
Aug 6th, 2009
0

Re: hi all please help me in this issue.

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
Featured Poster
Reputation Points: 1749
Solved Threads: 735
Senior Poster
sknake is offline Offline
3,948 posts
since Feb 2009
Aug 6th, 2009
0

Re: hi all please help me in this issue.

Thank you very much Sknake.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
bhas85 is offline Offline
4 posts
since Aug 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Shell Scripting Forum Timeline: Need some help with compression / move script
Next Thread in Shell Scripting Forum Timeline: Trimming some string using shell script





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC