pid 구하기

C++ 2012. 10. 10. 14:12

{

// 자신의 PID

HANDLE handle = GetCurrentProcess();

DWORD pid = GetProcessId(handle);

cout << "pid : " << pid << endl;

}

{

// 다른 아이 PID 구하기

DWORD pid = 0;

DWORD thread_id = GetWindowThreadProcessId((HWND)handle, &pid);

cout << "pid : " << pid << ", thrad_id : " << endl;

}


{

//모든 PID

void getCurrentPids(std::map<DWORD, std::string>& pids)

{

HANDLE handle = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);

if (handle == INVALID_HANDLE_VALUE) {

last_error_ = "fail CreateToolhelp32Snapshot";

return;

}

PROCESSENTRY32 ppe;

ppe.dwSize = sizeof(PROCESSENTRY32);


BOOL is_true = Process32First(handle, &ppe);

while (is_true) {

if (ppe.th32ProcessID != 0) { // [System Process] 제외

pids.insert(std::make_pair(ppe.th32ProcessID, ppe.szExeFile));

}

is_true = Process32Next(handle, &ppe);

}


CloseHandle(handle);

}


}

'C++' 카테고리의 다른 글

_time64로 초단위 로컬 현재 시간  (0) 2012.11.09
ip 목록 출력  (0) 2012.11.09
윈도우 서비스  (0) 2012.10.11
process kill 프로세스 죽이기  (0) 2012.10.10
현재 프로그램 경로  (0) 2012.10.05
for_each 와 boost bind  (0) 2012.09.07
FireBreath  (0) 2012.08.10
c++ logging library  (0) 2012.08.08