Skip to content

Instantly share code, notes, and snippets.

@nmilford
Created September 15, 2012 03:48
Show Gist options
  • Save nmilford/3726281 to your computer and use it in GitHub Desktop.
Save nmilford/3726281 to your computer and use it in GitHub Desktop.
Have your Clojure program generate a .pid file.
(ns io.milford.util
(:import [java.lang.management ManagementFactory]))
(defn get-pid []
"Gets this process' PID."
(let [pid (.getName (ManagementFactory/getRuntimeMXBean))]
(first (re-seq #"[0-9]+" pid))))
(defn write-pid-file [pid-file]
"Writes this process' PID to a supplied file name."
(spit pid-file (get-pid)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment