Get the shell that the supplied pid or os.getpid() is running in.

def get_shell(pid=None, max_depth=6):
    """Get the shell that the supplied pid or os.getpid() is running in.
    """
    pid = str(pid or os.getpid())
    mapping = _get_process_mapping()
    for proc_cmd in _iter_process_command(mapping, pid, max_depth):
        if proc_cmd.startswith('-'):    # Login shell! Let's use this.
            return _get_login_shell(proc_cmd)
        name = os.path.basename(proc_cmd).lower()
        if name in SHELL_NAMES:     # The inner-most (non-login) shell.
            return (name, proc_cmd)
    return None