Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- function check {
- if ! [ -f /run/user/1000/laba.pid ]; then
- return 1
- fi
- PID=`cat /run/user/1000/laba.pid`
- if [ -d /proc/$PID ]; then
- mes=`cat /proc/$PID/comm`
- if [[ $mes="sleep" ]] ;then
- return 0
- fi
- fi
- return 1
- }
- function start() {
- if check; then
- echo "The process already running."
- return
- fi
- (sleep 3600) & disown
- echo $! > /run/user/1000/laba.pid
- echo $!
- }
- function stop() {
- if check; then
- PID=`cat /run/user/1000/laba.pid`
- if ! kill -9 $PID 2>/dev/null; then
- echo "Unable to kill the process."
- fi
- rm -f /run/user/1000/laba.pid
- fi
- }
- function lab {
- if [[ "$1" = "start" ]]; then start
- elif [[ "$1" = "stop" ]]; then stop
- elif [[ "$1" = "restart" ]]; then stop
- start
- else
- echo "How to use:
- stop - stop the program
- start - start the program
- restart - restart the program"
- fi
- }
- lab "$1"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement