'get_pid(default = UNDEFINED)
Provides the process id of tor. This often only works if tor is running
locally. Also, most of its checks are platform dependent, and hence are not
entirely reliable.
.. versionadded:: 1.1.0
:param object default: response if the query fails
:returns: **int** for tor\'s pid
:raises: **ValueError** if unable to determine the pid and no default was
provided'

@with_default()
def get_pid(self, default=UNDEFINED):

    pid = self._get_cache('pid')
    if (not pid):
        getinfo_pid = self.get_info('process/pid', None)
        if (getinfo_pid and getinfo_pid.isdigit()):
            pid = int(getinfo_pid)
    if ((not pid) and self.is_localhost()):
        pid_file_path = self.get_conf('PidFile', None)
        if (pid_file_path is not None):
            with open(pid_file_path) as pid_file:
                pid_file_contents = pid_file.read().strip()
                if pid_file_contents.isdigit():
                    pid = int(pid_file_contents)
        if (not pid):
            pid = stem.util.system.pid_by_name('tor')
        if (not pid):
            control_socket = self.get_socket()
            if isinstance(control_socket, stem.socket.ControlPort):
                pid = stem.util.system.pid_by_port(control_socket.get_port())
            elif isinstance(control_socket, stem.socket.ControlSocketFile):
                pid = stem.util.system.pid_by_open_file(control_socket.get_socket_path())
    if pid:
        self._set_cache({'pid': pid})
        return pid
    else:
        raise ValueError(("Unable    to    resolve    tor's    pid" if self.is_localhost() else "Tor    isn't    running    locally"))
