A header-only C++23 library providing cross-platform process information with minimal footprint. Captures CPU, memory, and system details for the current process.
Features:
- Minimal footprint - header-only library
- Cross-platform support (Windows, Linux, macOS, Unix)
- JSON serialization via
nlohmann::json std::formatsupport for easy output- Single ownership semantics
CMake with CPM (Recommended)
CPMAddPackage("gh:SiddiqSoft/GenProcessInfo#main") // replace main with specific version
target_link_libraries(${PROJECT_NAME} INTERFACE GenProcessInfo::GenProcessInfo)NuGet (Windows)
Install-Package SiddiqSoft.WinProcessInfo
Manual
Copy include/siddiqsoft/GenProcessInfo.hpp to your project.
#include "siddiqsoft/GenProcessInfo.hpp"
int main() {
siddiqsoft::GenProcessInfo procInfo;
// Basic info available immediately
std::cout << "Process ID: " << procInfo.processId << "\n";
std::cout << "CPU Cores: " << procInfo.cpuCores << "\n";
// Expensive operation - call sparingly
procInfo.snapshot();
std::cout << "Memory: " << procInfo.memWorkingSet << " KB\n";
std::cout << "Threads: " << procInfo.cpuThreads << "\n";
return 0;
}JSON Output Example
#include <format>
#include "nlohmann/json.hpp"
#include "siddiqsoft/GenProcessInfo.hpp"
int main() {
siddiqsoft::GenProcessInfo procInfo;
procInfo.snapshot();
nlohmann::json j = procInfo;
std::cout << j.dump(2) << "\n";
return 0;
}- C++23 or later (MSVC 2022+, GCC 13+, Clang 17+)
- Windows 7+, Linux (with /proc), macOS 10.5+, or POSIX-compliant systems
- Optional:
nlohmann::jsonfor JSON serialization
| Platform | Status | Notes |
|---|---|---|
| Windows | ✓ Full | Windows 7 and later |
| Linux | ✓ Full | Requires /proc filesystem |
| macOS | ⚠ Limited | Thread count limited (requires Mach APIs) |
| Unix | ⚠ Limited | Generic POSIX fallback |
See API.md for comprehensive documentation including:
- All public members and methods
- Detailed parameter descriptions
- Platform-specific behavior
- Performance considerations
- Complete usage examples
- Thread safety notes
| Method | Description | Cost |
|---|---|---|
snapshot() |
Capture memory, handles, and thread count | Expensive |
uptime() |
Get elapsed time since object creation | Cheap |
getCurrentProcessId() |
Get current process ID (static) | Cheap |
| Member | Type | Description |
|---|---|---|
processId |
unsigned long |
Current process ID |
cpuCores |
unsigned long |
Available CPU cores |
cpuThreads |
unsigned long |
Process thread count |
cpuHandles |
unsigned long |
Open handles/file descriptors |
memWorkingSet |
size_t |
Current memory in KB |
memPeakWorkingSet |
size_t |
Peak memory in KB |
memPrivate |
size_t |
Private memory in KB |
nameHostname |
std::string |
DNS hostname |
nameFqdn |
std::string |
Fully qualified domain name |
See API.md for complete member documentation.
Performance Tips
- Reuse instances - Create once, call
snapshot()periodically - Background thread - Call
snapshot()in a low-priority background thread - Cache results - Store values if frequent access is needed
- Avoid copies - Copy/move operations are deleted (single ownership)
Backward Compatibility
The library provides WinProcessInfo as an alias for GenProcessInfo:
siddiqsoft::WinProcessInfo procInfo; // Legacy name still worksLicense
BSD 3-Clause License - See LICENSE file
© 2021 Siddiq Software LLC. All rights reserved.