Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. function check {
  4. if ! [ -f /run/user/1000/laba.pid ]; then
  5. return 1
  6. fi
  7.  
  8. PID=`cat /run/user/1000/laba.pid`
  9. if [ -d /proc/$PID ]; then
  10. mes=`cat /proc/$PID/comm`
  11. if [[ $mes="sleep" ]] ;then
  12. return 0
  13. fi
  14. fi
  15.  
  16. return 1
  17. }
  18.  
  19. function start() {
  20. if check; then
  21. echo "The process already running."
  22. return
  23. fi
  24.  
  25. (sleep 3600) & disown
  26. echo $! > /run/user/1000/laba.pid
  27. echo $!
  28.  
  29. }
  30.  
  31. function stop() {
  32. if check; then
  33. PID=`cat /run/user/1000/laba.pid`
  34. if ! kill -9 $PID 2>/dev/null; then
  35. echo "Unable to kill the process."
  36. fi
  37. rm -f /run/user/1000/laba.pid
  38. fi
  39. }
  40.  
  41. function lab {
  42. if [[ "$1" = "start" ]]; then start
  43. elif [[ "$1" = "stop" ]]; then stop
  44. elif [[ "$1" = "restart" ]]; then stop
  45. start
  46. else
  47. echo "How to use:
  48. stop - stop the program
  49. start - start the program
  50. restart - restart the program"
  51. fi
  52. }
  53. lab "$1"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement