Quick Links:

bal | bbl | bdl | bsl

Namespaces

Component bdls_processutil
[Package bdls]

Provide basic platform-independent utilities related to processes. More...

Namespaces

namespace  bdls

Detailed Description

Outline
Purpose:
Provide basic platform-independent utilities related to processes.
Classes:
bdls::ProcessUtil portable utility methods related to processes
See also:
Description:
This component, bdls::ProcessUtil, defines a platform-independent interface for processes. Currently, it provides a utility to get the current process ID, a utility to get the name of the process, and a utility to get a filename through which the executable can be accessed.
getProcessName vs getPathToExecutable:
The getProcessName function is intended to yield a process name that will be meaningful to the programmer, recognizably related to the value of argv[0] passed to the application, and usually a valid path to the executable file. However, in some cases, especially when argv[0] was a relative path and the working directory has changed since main was called, this will not be a usable path for accessing the executable file, and getPathToExecutable should be used. Note that the return value of getPathToExecutable may be completely unrelated to the value of argv[0] passed to main, and the value returned by that function may vary when called multiple times in the same program. getPathToExecutable will not succeed unless it returns a valid path to the executable file.
Usage:
Get the current process ID:
  const int pid = bdls::ProcessUtil::getProcessId();
All calls to getProcessId will yield the same value: Get the current process name:
  bsl::string processName;
  int rc = bdls::ProcessUtil::getProcessName(&processName);
  if (0 != rc) {
      processName = "unknown";
  }
All calls to getProcessName will yield the same value. Note that if the call does not succeed, processNameB will not be modified.
  bsl::string processNameB("unknown");
  (void) bdls::ProcessUtil::getProcessName(&processNameB);

  assert(processNameB == processName);