Get the shell that the supplied pid or os.getpid() is running in.
187338
def get_shell(pid=None, max_depth=6):
    
    if not pid:
        pid = os.getpid()
    processes = dict(_iter_process())

    def check_parent(pid, lvl=0):
        ppid = processes[pid].get('parent_pid')
        shell_name = _get_executable(processes.get(ppid))
        if shell_name in SHELL_NAMES:
            return (shell_name, processes[ppid]['executable'])
        if lvl >= max_depth:
            return None
        return check_parent(ppid, lvl=lvl + 1)

    shell_name = _get_executable(processes.get(pid))
    if shell_name in SHELL_NAMES:
        return (shell_name, processes[pid]['executable'])
    try:
        return check_parent(pid)
    except KeyError:
        return None
669519
public static String getPid(EvaluationCtx context) {
        EvaluationResult attribute
                = context.getResourceAttribute(STRING_ATTRIBUTE,
                        Constants.OBJECT.PID.attributeId,
                                               null);
        BagAttribute element = getAttributeFromEvaluationResult(attribute);
        if (element == null) {
            logger.debug("PolicyFinderModule:getPid exit on can't get pid on request callback");
            return null;
        }

        if (!(element.getType().equals(STRING_ATTRIBUTE))) {
            logger.debug("PolicyFinderModule:getPid exit on couldn't get pid from xacml request non-string returned");
            return null;
        }

        return (element.size() == 1) ? (String) element.getValue() : null;
    }
1063368
def get_process(cmd):
    """"""

    if sys.platform.startswith('win'):
        startupinfo = subprocess.STARTUPINFO()
        startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
        process = subprocess.Popen(
            cmd,
            startupinfo=startupinfo,
            stdout=subprocess.PIPE,
            stderr=subprocess.STDOUT,
            stdin=subprocess.PIPE,
            shell=False
        )
    else:
        process = subprocess.Popen(
            cmd,
            stdout=subprocess.PIPE,
            stderr=subprocess.STDOUT,
            stdin=subprocess.PIPE,
            shell=False
        )
    return process
590123
def get_process_mapping():
    
    stat_name = detect_proc()
    self_tty = _get_stat(os.getpid(), stat_name)[0]
    processes = {}
    for pid in os.listdir('/proc'):
        if not pid.isdigit():
            continue
        try:
            tty, ppid = _get_stat(pid, stat_name)
            if tty != self_tty:
                continue
            args = _get_cmdline(pid)
            processes[pid] = Process(args=args, pid=pid, ppid=ppid)
        except IOError:
            # Process has disappeared - just ignore it.
            continue
    return processes
763636
def shell(source=None, vars=None, server=None, port=None):
    """"""
    Wdb.get(server=server, port=port).shell(source=source, vars=vars)
356552
def get_pid(rundir, process_type=PROCESS_TYPE, name=None):
    
    pidPath = get_pidpath(rundir, process_type, name)
    log.log('run', 'pidfile for %s %s is %s' % (process_type, name, pidPath))

    if not os.path.exists(pidPath):
        return

    pidFile = open(pidPath, 'r')
    pid = pidFile.readline()
    pidFile.close()
    if not pid or int(pid) == 0:
        return

    return int(pid)
1199202
def shell(self):
        
        from rez.shells import get_shell_types
        shells = set(get_shell_types())
        if not shells:
            raise RezSystemError("no shells available")

        if self.platform == "windows":
            return "cmd"
        else:
            import subprocess as sp
            shell = None

            # check parent process via ps
            try:
                args = ['ps', '-o', 'args=', '-p', str(os.getppid())]
                proc = sp.Popen(args, stdout=sp.PIPE)
                output = proc.communicate()[0]
                shell = os.path.basename(output.strip().split()[0]).replace('-', '')
            except Exception:
                pass

            # check $SHELL
            if shell not in shells:
                shell = os.path.basename(os.getenv("SHELL", ''))

            # traverse parent procs via /proc/(pid)/status
            if shell not in shells:
                pid = str(os.getppid())
                found = False

                while not found:
                    try:
                        file = os.path.join(os.sep, "proc", pid, "status")
                        with open(file) as f:
                            loc = f.read().split('\n')

                        for line in loc:
                            line = line.strip()
                            toks = line.split()
                            if len(toks) == 2:
                                if toks[0] == "Name:":
                                    name = toks[1]
                                    if name in shells:
                                        shell = name
                                        found = True
                                        break
                                elif toks[0] == "PPid:":
                                    pid = toks[1]
                    except Exception:
                        break

            if (shell not in shells) and ("sh" in shells):
                shell = "sh"  # failed detection, fall back on 'sh'
            elif (shell not in shells) and ("bash" in shells):
                shell = "bash"  # failed detection, fall back on 'bash'
            elif shell not in shells:
                shell = iter(shells).next()  # give up - just choose a shell

            # sh has to be handled as a special case
            if shell == "sh":
                if os.path.islink("/bin/sh"):
                    path = os.readlink("/bin/sh")
                    shell2 = os.path.split(path)[-1]

                    if shell2 == "bash":
                        # bash switches to sh-like shell when invoked as sh,
                        # so we want to use the sh shell plugin
                        pass
                    elif shell2 == "dash":
                        # dash doesn't have an sh emulation mode, so we have
                        # to use the dash shell plugin
                        if "dash" in shells:
                            shell = "dash"
                        else:
                            # this isn't good!
                            if "bash" in shells:
                                shell = "bash"  # fall back on bash
                            else:
                                shell = iter(shells).next()  # give up - just choose a shell

            # TODO: remove this when/if dash support added
            if shell == "dash":
                shell = "bash"

            return shell
743141
def get_pidpath(rundir, process_type, name=None):
    
    assert rundir, "rundir is not configured"
    path = os.path.join(rundir, '%s.pid' % process_type)
    if name:
        path = os.path.join(rundir, '%s.%s.pid' % (process_type, name))
    log.log('common', 'get_pidpath for type %s, name %r: %s'
            % (process_type, name, path))
    return path
81606
def pid(self):
        """"""
        try:
            return self._pid
        except AttributeError:
            self._pid = os.getpid()
            return self._pid
1232420
public static int getPid()
	{
		String pid = ManagementFactory.getRuntimeMXBean().getName();
		int indexOf = pid.indexOf('@');
		if (indexOf > 0) {
			pid = pid.substring(0, indexOf);
		}
		return Integer.parseInt(pid);
	}
706743
private static Long getPid(File pidFile) {
      FileReader reader = null;
      BufferedReader lineReader = null;
      String pidLine  = null;
      try {
        reader = new FileReader(pidFile);
        lineReader = new BufferedReader(reader);
        pidLine = lineReader.readLine();
        if(pidLine!=null) {
          pidLine = pidLine.trim();     
        }   
      } catch (Exception ex) {
        log.error("Failed to read PID from file  [" + pidFile.getAbsolutePath() + "]", ex);
      } finally {
        if(reader!=null) try { reader.close(); } catch (Exception ex) { /* No Op */ }
      }
      try {
        return Long.parseLong(pidLine);
      } catch (Exception ex) {
        return null;
      }     
    }
889177
def get_pid(name, path=None):
    '''
    
    '''
    if name not in list_(limit='running', path=path):
        raise CommandExecutionError('Container {0} is not running, can\'t determine PID'.format(name))
    info = __salt__['cmd.run']('lxc-info -n {0}'.format(name)).split("\n")
    pid = [line.split(':')[1].strip() for line in info if re.match(r'\s*PID', line)][0]
    return pid
831305
def get(name):
    '''
    
    '''
    cmd = 'sysctl -n {0}'.format(name)
    out = __salt__['cmd.run'](cmd, python_shell=False)
    return out
527549
def get_pid(options):
    """"""
    namespace = options['settings'] if options['settings'] else options['wsgi']
    return os.path.join('{}', '{}_{}.pid').format(PID_DIR, options['http_port'], namespace.replace('.', '_'))
1088415
public static String getPid() {
        if (pid == null) {
            String runtimeName = ManagementFactory.getRuntimeMXBean().getName();
            if (runtimeName == null) {
                pid = "unknown";
            } else {
                int index = runtimeName.indexOf('@');
                if (index < 0) {
                    pid = runtimeName;
                } else {
                    pid = runtimeName.substring(0, index);
                }
            }
        }
        return pid;
    }
73909
private static function getPid()
    {
        if (!is_file(self::$pidFile)) {
            return 0;
        }

        $pid = intval(file_get_contents(self::$pidFile));
        return $pid;
    }
81153
public function getPid()
    {
        $options = static::getOptions();
        $debug = @$options['debug'] === true;

        $pidFile = $options['pid_file'];
        if (!$pidFile)
            throw new \Exception("No pid_file in the config");

        $fpPid = fopen($pidFile, "c");
        if (!$fpPid)
            throw new \Exception("Could not open " . $pidFile);

        if (!flock($fpPid, LOCK_EX | LOCK_NB)) {
            fclose($fpPid);
            return (int)file_get_contents($pidFile);
        }

        flock($fpPid, LOCK_UN);
        fclose($fpPid);
        @unlink($pidFile);
        return false;
    }