async function getPidUsingPattern (pgrepPattern) {
  const args = ['-nif', pgrepPattern];
  try {
    const {stdout} = await exec('pgrep', args);
    const pid = parseInt(stdout, 10);
    if (isNaN(pid)) {
      log.debug(`Cannot parse process id from 'pgrep ${args.join(' ')}' output: ${stdout}`);
      return null;
    }
    return `${pid}`;
  } catch (err) {
    log.debug(`'pgrep ${args.join(' ')}' didn't detect any matching processes. Return code: ${err.code}`);
    return null;
  }
}
async function getPidUsingPattern (pgrepPattern) {
  const args = ['-nif', pgrepPattern];
  try {
    const {stdout} = await exec('pgrep', args);
    const pid = parseInt(stdout, 10);
    if (isNaN(pid)) {
      log.debug(`Cannot parse process id from 'pgrep ${args.join(' ')}' output: ${stdout}`);
      return null;
    }
    return `${pid}`;
  } catch (err) {
    log.debug(`'pgrep ${args.join(' ')}' didn't detect any matching processes. Return code: ${err.code}`);
    return null;
  }
}
async function getPidUsingPattern ( pgrepPattern ) { const args = [ '-nif' , pgrepPattern ] ; try { const { stdout } = await exec ( 'pgrep' , args ) ; const pid = parseInt ( stdout , 10 ) ; if ( isNaN ( pid ) ) { log . debug ( ` ${ args . join ( ' ' ) } ${ stdout } ` ) ; return null ; } return ` ${ pid } ` ; } catch ( err ) { log . debug ( ` ${ args . join ( ' ' ) } ${ err . code } ` ) ; return null ; } }
Get the process id of the most recent running application
having the particular command line pattern.

@param {string} pgrepPattern - pgrep-compatible search pattern.
@return {string} Either a process id or null if no matches were found.
Get the process id of the most recent running application having the particular command line pattern .