Provide utilities related to the operating system.
More...
Namespaces |
namespace | bdls |
Detailed Description
- Outline
-
-
- Purpose:
- Provide utilities related to the operating system.
-
- Classes:
bdls::OsUtil | namespace for operating system information utilities |
- See also:
-
- Description:
- This component provides a namespace,
bdls::OsUtil
, containing utility functions for retrieving information at runtime about the operating system in which this task is running.
-
- Usage:
- This section illustrates intended use of this component.
-
- Example 1: Display OS Name, Version and Patch Level:
- The following example demonstrates using
getOsInfo
to obtain information about the operating system at runtime and writing it to the console.
- First, we create strings for the operating system name (
osName
), version (osVersion
), and patch (osPatch
), and then call getOsInfo
to load these strings with values for the operating system the task is executing in: Then, we use the standard streams to write the operating system version information to the console, or an error message of failure: const int rc = bdls::OsUtil::getOsInfo(&name, &version, &patch);
if (rc == 0) {
bsl::cout << "OS Name: " << name << "\n"
<< "Version: " << version << "\n"
<< "Patch: " << patch << "\n";
} else {
bsl::cout << "Cannot determine OS name and version\n";
}
Finally, the resulting console output on the Red Hat Enterprise Linux Server 5.5 would be OS Name: Linux
Version: 2.6.18-194.32.1.el5
Patch: #1 SMP Mon Dec 20 10:52:42 EST 2010
On Windows 7 SP1, the display would be OS Name: Windows
Version: 6.1
Patch: Service Pack 1