Give me a C++ code to list running processes on Windows
- User
Give me a C++ code to list running processes on Windows
Assistant
Sure! Here's an example code in C++ that uses the Windows operating system to list all currently running processes:
#include <Windows.h> #include <vector> using namespace std; int main() { vector<pid_t> processes; DWORD pid = 0; GetCurrentProcessId(NULL, &pid, &processes); for (auto process : processes) { if (process->thr_pid == pid) { cout << "Process " << process->thr_pid << " is currently running."; break; } } return 0; }This code uses the
GetCurrentProcessIdfunction to get a pointer to aDWORDvalue that represents the process ID of the currently running process. It then loops through all processes in theprocessesvector and checks if the process ID matches thepidvalue of the last process in theprocessesvector. If a match is found, the program will output "Process " followed by the process ID and " is currently running." and exit.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.