BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bdls_processutil

Detailed Description

Outline

Purpose

Provide basic platform-independent utilities related to processes.

Classes

See also
bdls_filesystemutil

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

This section illustrates intended use of this component.

Example 1: Basic Usage

Get the current process ID:

static int 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";
}
Definition bslstl_string.h:1281
static int getProcessName(bsl::string *result)

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);