System Information Using C/C++


What would be the header files and the suitable codes required for generating system calls in C++ for the below mentioned purposes:-
a. Number of Processes running in the system
b. Number of Zombie Processes in the system
c. Details of each of the processes:
d. Process Name,
e. Process Class (Time sharing class, real-time class, etc.),
f. Process State (sleeping, running, waiting for IO, etc),
g. Process Priority,
h. % of CPU Used
i. CPU Time used by the process in User, Kernel
j. Number of file descriptors opened by the process
k. Listing of Opened files, sockets, pipes, devices
l. Virtual address map of the libraries, files
m. Signals pending, blocked on the process
n. Stack trace of the process or threads


PLS DO reply . ANy reference to any site would be immensely helpful where i can view such sample codes . This is exclusively for windows enviornment system.

Dani AI

Generated

Short practical roadmap (Windows) for . is right that a few items you listed are Unix concepts and have no direct 1:1 equivalent on Windows. 's CodeProject pointer helps for process enumeration, but for robust tooling prefer the documented Windows APIs and tools below.

Enumerate PIDs with Tool Help or PSAPI or WMI (CreateToolhelp32Snapshot, EnumProcesses/PSAPI, Win32_Process WMI class). Open processes with OpenProcess to call: process name via QueryFullProcessImageName/GetModuleFileNameEx (EnumProcessModules), priority class via GetPriorityClass, user/kernel CPU times via GetProcessTimes and system totals via . Virtual memory map: VirtualQueryEx. Open-file/socket lists require other tools: Sysinternals Handle for handles/files (Handle), Restart Manager or IP Helper APIs for TCP/UDP (GetExtendedTcpTable). Windows has no POSIX-style signals or zombies; infer state from threads and object handles. Stack traces need the Debug Help API/StackWalk64 (StackWalk64) and proper privileges/symbols.

Notes: many queries need PROCESS_QUERY_INFORMATION/PROCESS_VM_READ or SE_DEBUG_NAME and careful 32/64-bit handling. WMI is easiest but slower; native APIs are faster. CPU percent example (sample two snapshots and compute deltas):

procDelta = (procUser + procKernel) - (prevProcUser + prevProcKernel)
sysDelta  = (sysUser + sysKernel) - (prevSysUser + prevSysKernel)
cpuPct = 100.0 * procDelta / sysDelta  // FILETIME units (100 ns)

Recommended Answers

All 2 Replies

is how to get a list of processes in MS-Windows. Don't know how to get the rest of the info you need.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.