+# Returns PID of currently running process, if any
+getpid() {
+
+ if [ -f "$pidfile" ]
+ then
+
+ read PID < "$pidfile"
+
+ # If pidfile contains PID and PID is valid
+ if [ -n "$PID" ] && ps "$PID" > /dev/null 2>&1
+ then
+ echo "$PID"
+ return 0
+ fi
+
+ fi
+
+ # pidfile/pid not found, or process is dead
+ return 1
+
+}
+