Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@marzzz21
Created August 26, 2016 06:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marzzz21/80563914cd168b3857767851894b9fc1 to your computer and use it in GitHub Desktop.
Save marzzz21/80563914cd168b3857767851894b9fc1 to your computer and use it in GitHub Desktop.
def check_status
~ |+ if File.exists?(PID_FILE)
~ |+ pid = File.read(PID_FILE).to_i
~ |+ check_pid_status(pid) if pid > 0
~ |+ File.delete(PID_FILE)
~ |+ end
~ |+ end
~ |+
~ |+ def check_pid_status(pid)
~ |+ Process.kill(0, pid)
~ |+ puts "Process(#{pid}) is already running."
~ |+ exit(1)
~ |+ rescue Errno::ESERCH #do nothing, and continue with the script
~ |+ rescue Errno::EPERM
~ |+ puts "Process with pid=#{pid} is already running but is owned by a different user"
~ |+ exit(1)
~ |+ end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment