공부방/Delphi
[델파이] 특정프로세스 쓰레드 개수(Thread Count) 조회
래채
2023. 12. 28. 11:48
use!
uses
Windows, TlHelp32;
function 정의!
function GetThreadCount(ProcessID: DWORD): Integer;
var
Snapshot: THandle;
ThreadEntry: TThreadEntry32;
begin
Result := 0;
Snapshot := CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0);
if Snapshot <> INVALID_HANDLE_VALUE then
try
ThreadEntry.dwSize := SizeOf(ThreadEntry);
if Thread32First(Snapshot, ThreadEntry) then
repeat
if ThreadEntry.th32OwnerProcessID = ProcessID then
Inc(Result);
until not Thread32Next(Snapshot, ThreadEntry);
finally
CloseHandle(Snapshot);
end;
end;
호출 예시!
var
ProcessID: DWORD;
ThreadCount: Integer;
begin
ProcessID := GetCurrentProcessId; // 현재 프로세스 ID를 얻습니다.
ThreadCount := GetThreadCount(ProcessID);
// 이제 ThreadCount 변수에 특정 프로세스의 스레드 수가 저장됩니다.
end;
출처 : 우리의 친구 chatGPT