Skip to content

SiddiqSoft/GenProcessInfo

Repository files navigation

ProcessInfo : Cross-Platform Process Information

CodeQL Build Status

Overview

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::format support for easy output
  • Single ownership semantics

Quick Start

Installation

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.

Basic Usage

#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;
}

Requirements

  • C++23 or later (MSVC 2022+, GCC 13+, Clang 17+)
  • Windows 7+, Linux (with /proc), macOS 10.5+, or POSIX-compliant systems
  • Optional: nlohmann::json for JSON serialization

Platform Support

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

API Reference

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

Key Methods

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

Key Members

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
  1. Reuse instances - Create once, call snapshot() periodically
  2. Background thread - Call snapshot() in a low-priority background thread
  3. Cache results - Store values if frequent access is needed
  4. 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 works
License

BSD 3-Clause License - See LICENSE file


© 2021 Siddiq Software LLC. All rights reserved.

About

Linux and Windows Process Information utility class

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors