hi all please help me in this issue.

Please support our Shell Scripting advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Aug 2009
Posts: 4
Reputation: bhas85 is an unknown quantity at this point 
Solved Threads: 0
bhas85 bhas85 is offline Offline
Newbie Poster

hi all please help me in this issue.

 
0
  #1
Aug 4th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 3,464
Reputation: sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of 
Solved Threads: 629
Sponsor
sknake's Avatar
sknake sknake is offline Offline
.NET Enthusiast

Re: hi all please help me in this issue.

 
0
  #2
Aug 6th, 2009
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.
Scott Knake
Custom Software Development
Apex Software, Inc.
Reply With Quote Quick reply to this message  
Join Date: Aug 2009
Posts: 4
Reputation: bhas85 is an unknown quantity at this point 
Solved Threads: 0
bhas85 bhas85 is offline Offline
Newbie Poster

Re: hi all please help me in this issue.

 
0
  #3
Aug 6th, 2009
Originally Posted by sknake View Post
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.
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 3,464
Reputation: sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of 
Solved Threads: 629
Sponsor
sknake's Avatar
sknake sknake is offline Offline
.NET Enthusiast

Re: hi all please help me in this issue.

 
0
  #4
Aug 6th, 2009
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
Scott Knake
Custom Software Development
Apex Software, Inc.
Reply With Quote Quick reply to this message  
Join Date: Aug 2009
Posts: 4
Reputation: bhas85 is an unknown quantity at this point 
Solved Threads: 0
bhas85 bhas85 is offline Offline
Newbie Poster

Re: hi all please help me in this issue.

 
0
  #5
Aug 6th, 2009
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,
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 3,464
Reputation: sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of 
Solved Threads: 629
Sponsor
sknake's Avatar
sknake sknake is offline Offline
.NET Enthusiast

Re: hi all please help me in this issue.

 
0
  #6
Aug 6th, 2009
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
Scott Knake
Custom Software Development
Apex Software, Inc.
Reply With Quote Quick reply to this message  
Join Date: Aug 2009
Posts: 4
Reputation: bhas85 is an unknown quantity at this point 
Solved Threads: 0
bhas85 bhas85 is offline Offline
Newbie Poster

Re: hi all please help me in this issue.

 
0
  #7
Aug 6th, 2009
Thank you very much Sknake.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Shell Scripting Forum


Views: 567 | Replies: 6
Thread Tools Search this Thread



Tag cloud for Shell Scripting
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC