def get_uptime():
    cmd = ["/usr/sbin/sysctl", "-n", "kern.boottime"]
    proc = subprocess.Popen(
        cmd,
        shell=False,
        bufsize=-1,
        stdin=subprocess.PIPE,
        stdout=subprocess.PIPE,
        stderr=subprocess.PIPE,
    )
    (output, unused_error) = proc.communicate()
    sec = int(re.sub(".*sec = (\d+),.*", "\\1", output))
    up = int(time.time() - sec)
    return up if up > 0 else -1