Get package name of the process id.
@param context the context.
@param pid the process id.
@return the package name for the process id. {@code null} if no process found.
763240
public static String getPackageNameFromPid(Context context, int pid) {
        ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
        List<RunningAppProcessInfo> processes = am.getRunningAppProcesses();
        for (RunningAppProcessInfo info : processes) {
            if (info.pid == pid) {
                String[] packages = info.pkgList;
                if (packages.length > 0) {
                    return packages[0];
                }
                break;
            }
        }
        return null;
    }
583251
public static String generateUserAgent(Context context) {
        StringBuilder ua = new StringBuilder("api-client/");
        ua.append(VERSION);

        String packageName = context.getApplicationContext().getPackageName();

        ua.append(" ");
        ua.append(packageName);

        PackageInfo pi = null;
        try {
            pi = context.getPackageManager().getPackageInfo(packageName, 0);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        if (pi != null) {
            ua.append("/");
            ua.append(pi.versionName);
            ua.append("(");
            ua.append(pi.versionCode);
            ua.append(")");
        }
        ua.append(" Android/");
        ua.append(Build.VERSION.SDK_INT);

        try {
            ua.append(" ");
            ua.append(Build.PRODUCT);
        } catch (Exception e) {
            e.printStackTrace();
        }

        try {
            ua.append(" ");
            ua.append(Build.MANUFACTURER);
        } catch (Exception e) {
            e.printStackTrace();
        }

        try {
            ua.append(" ");
            ua.append(Build.MODEL);
        } catch (Exception e) {
            e.printStackTrace();
        }

        return ua.toString();
    }
277791
private static final String getFilenameFromId(String pid, String dsid, String MIMETYPE) throws Exception {
        return dsid;
    }
1129916
public static String getVersionCode(Context context) {
        if (sVersion == null) {
            try {
                sVersion = context.getPackageManager().getPackageInfo(
                        context.getPackageName(), 0).versionName;
            } catch (PackageManager.NameNotFoundException e) {
                // Can't find version; just leave it blank.
                Log.e(TAG, "Error finding package " + context.getApplicationInfo().packageName);
            }
        }
        return sVersion;
    }
615922
def getpcmd(pid):
    
    if os.name == "nt":
        # Use wmic command instead of ps on Windows.
        cmd = 'wmic path win32_process where ProcessID=%s get Commandline 2> nul' % (pid, )
        with os.popen(cmd, 'r') as p:
            lines = [line for line in p.readlines() if line.strip("\r\n ") != ""]
            if lines:
                _, val = lines
                return val
    elif sys.platform == "darwin":
        # Use pgrep instead of /proc on macOS.
        pidfile = ".%d.pid" % (pid, )
        with open(pidfile, 'w') as f:
            f.write(str(pid))
        try:
            p = Popen(['pgrep', '-lf', '-F', pidfile], stdout=PIPE)
            stdout, _ = p.communicate()
            line = stdout.decode('utf8').strip()
            if line:
                _, scmd = line.split(' ', 1)
                return scmd
        finally:
            os.unlink(pidfile)
    else:
        # Use the /proc filesystem
        # At least on android there have been some issues with not all
        # process infos being readable. In these cases using the `ps` command
        # worked. See the pull request at
        # https://github.com/spotify/luigi/pull/1876
        try:
            with open('/proc/{0}/cmdline'.format(pid), 'r') as fh:
                if six.PY3:
                    return fh.read().replace('\0', ' ').rstrip()
                else:
                    return fh.read().replace('\0', ' ').decode('utf8').rstrip()
        except IOError:
            # the system may not allow reading the command line
            # of a process owned by another user
            pass

    # Fallback instead of None, for e.g. Cygwin where -o is an "unknown option" for the ps command:
    return '[PROCESS_WITH_PID={}]'.format(pid)
252023
private void getControllingProcessDirectory(long timestamp, String pid) {
		int count = 0;
		while (ivSubDirectory == null) {
			ivSubDirectory = makeLogDirectory(timestamp, pid);
			if (ivSubDirectory == null) {
				if (++count > FAILED_MAX_COUNT) {
					ivSubDirectory = makeLogDirectory(timestamp, pid,true);
					if(ivSubDirectory==null){
						if (debugLogger.isLoggable(Level.FINE) && isDebugEnabled())
						{
							debugLogger.logp(Level.FINE, thisClass, "UnableToMakeDirectory", "Unable to create instance directory forcefully , throwing Runtime Exception");
						}
					  throw new RuntimeException("Failed to create instance log repository. See SystemOut.log for details.");
				    }
				}
				try {
					Thread.sleep(FAILED_WAIT_TIME);
				} catch (InterruptedException ex) {
					// Ignore it, assume that we had enough sleep.
				}
			}
		}
	}
107895
private String getProcessName(ProcessTextProvider textProvider)
    {
		if (!quotedString('"',textProvider))
		{
			return "P"+(textProvider.incrementProcessCount());
		}
    	if (textProvider.getLastToken().contains("_"))
    	{
    		throw new ParserException("Process names nust not include underbar: "+textProvider.getLastToken());
    	}
    	return textProvider.getLastToken();
    }
1291483
public final ChooseableSpecifics findChSpecificsById(
    final List<ChooseableSpecifics> pListChSpecifics,
      final Long pId) {
    for (ChooseableSpecifics chs : pListChSpecifics) {
      if (chs.getItsId().equals(pId)) {
        return chs;
      }
    }
    return null;
  }
141344
protected String getIdForNewProcessDefinition(ProcessDefinitionEntity processDefinition) {
        String nextId = idGenerator.getNextId();

        String result = processDefinition.getKey() + ":" + processDefinition.getVersion() + ":" + nextId; // ACT-505
        // ACT-115: maximum id length is 64 characters
        if (result.length() > 64) {
            result = nextId;
        }

        return result;
    }
210645
public static int getAppVersion(@NonNull final Context context) {
        try {
            final PackageInfo packageInfo = context.getPackageManager()
                    .getPackageInfo(context.getPackageName(), 0);
            return packageInfo.versionCode;
        } catch (PackageManager.NameNotFoundException ignore) {
            // ignore
        }

        return Integer.MIN_VALUE;
    }
362616
String lookupPid(ConfigID referenceId) {
        ExtendedConfiguration config = caSupport.lookupConfiguration(referenceId);
        String pid = (config == null) ? null : config.getPid();
        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
            Tr.debug(tc, "lookupPid(): Lookup of " + referenceId + " reference resolved to " + pid);
        }
        return pid;
    }
1234853
String packageName() {
    for (Object context : contextStack) {
      if (context instanceof ProtoFile) return ((ProtoFile) context).packageName();
    }
    return null;
  }
836960
def get_context(pid_file, daemon=False):
    
    port_file = get_context_file_name(pid_file)

    if not os.path.exists(port_file):
        return None

    with open(port_file, "rt") as f:
        json_data = f.read()
        try:
            data = json.loads(json_data)
        except ValueError as e:

            logger.error("Damaged context json data %s", json_data)
            return None

        if not daemon:
            pid = data.get("pid")
            if pid and not check_pid(int(pid)):
                # The Notebook daemon has exited uncleanly, as the PID does not point to any valid process
                return None

        return data
1338704
public synchronized Properties getProcessProperties(final String processName) {
        final NamedProcess namedProcess = processes.get(processName);
        return namedProcess == null ? null : namedProcess.getProperties();
    }
1292993
def get_process_info(self, pid=None):
        '''
        

        '''

        pid = self._get_pid(pid)
        return self._call_rest_api('get', '/processes/'+pid, error='Failed to fetch process information')
472070
@Override
    public List<String> getObjectHistory(String pid) {
        MessageContext ctx = context.getMessageContext();
        Context context = ReadOnlyContext.getSoapContext(ctx);
        assertInitialized();
        try {
            String[] changeTimestamps = m_access.getObjectHistory(context, pid);
            if (changeTimestamps != null && debug) {
                for (int i = 0; i < changeTimestamps.length; i++) {
                    LOG.debug("changeTimestamps[{}] = {}", i, changeTimestamps[i]);
                }
            }
            return changeTimestamps == null ? null : Arrays.asList(changeTimestamps);
        } catch (Throwable th) {
            LOG.error("Error getting object history", th);
            throw CXFUtility.getFault(th);
        }
    }
1011458
def pid_from_context(_, context):
    """"""
    pid = (context or {}).get('pid')
    return pid.pid_value if pid else missing