Advertisement
Guest User

Untitled

a guest
May 27th, 2016
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. #!/usr/bin/perl
  2. # Simple script to run a sub-process in a loop
  3.  
  4. use POSIX;
  5.  
  6. $dead = 0;
  7.  
  8. $SIG{'TERM'} = sub { $dead = 1;
  9. if ($childpid) {
  10. kill(TERM, $childpid);
  11. sleep(1); # Give it time to clean up
  12. kill(KILL, $childpid);
  13. }
  14. exit(1);
  15. };
  16.  
  17. while(!$dead) {
  18. $start = time();
  19. $childpid = fork();
  20. if ($childpid == 0) {
  21. exec(@ARGV);
  22. }
  23. waitpid($childpid, 0);
  24.  
  25. if (time() - $start < 10) {
  26. # Crashed within 10 seconds .. throttle restart
  27. sleep(5);
  28. }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement