이거 안 해주면... Task Manager에서 확인하면 Handle 값이 계속해서 2개씩 증가하는 것을 확인할 수 있습니다.
MSDN에 보면... 이런 글이 있습니다.
Handles in PROCESS_INFORMATION must be closed with CloseHandle when they are no longer needed.
물론, 이 CreateProcess를 호출하는 Process가 한 번 실행 되었다가 종료되면 모르지만, 계속 실행하는 Service나 기타 다른 프로그램이라면, 주의할 대목입니다.
그리고 보면, 참 생각없이 코딩했다는 생각이 드네요...
MSDN의 Sample을 볼까요?
#include <windows.h>
#include <stdio.h>
#include <tchar.h>
void _tmain( int argc, TCHAR *argv[] )
{
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) );
if( argc != 2 )
{
printf("Usage: %s [cmdline]\n", argv[0]);
return;
}
// Start the child process.
if( !CreateProcess( NULL, // No module name (use command line)
argv[1], // Command line
NULL, // Process handle not inheritable
NULL, // Thread handle not inheritable
FALSE, // Set handle inheritance to FALSE
0, // No creation flags
NULL, // Use parent's environment block
NULL, // Use parent's starting directory
&si, // Pointer to STARTUPINFO structure
&pi ) // Pointer to PROCESS_INFORMATION structure
)
{
printf( "CreateProcess failed (%d)\n", GetLastError() );
return;
}
// Wait until child process exits.
WaitForSingleObject( pi.hProcess, INFINITE );
// Close process and thread handles.
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );
}
댓글 없음:
댓글 쓰기