Created
September 15, 2012 03:48
-
-
Save nmilford/3726281 to your computer and use it in GitHub Desktop.
Have your Clojure program generate a .pid file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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