c++ 可执行文件的进程未正确关闭

Process of c++ executable doesn't close correctly

本文关键字:可执行文件 进程 c++      更新时间:2023-10-16

在我的程序中,我在同一窗口中启动其他C 应用程序,以关闭上一个。有时,我在任务管理器中看到的过程不会关闭。因此,我将有许多同名的过程。我如何避免这种情况?

startup("../folder/c++_executable.exe");
exit(0);
void startup(LPCTSTR lpApplicationName)
{
   // additional information
   STARTUPINFO si;
   PROCESS_INFORMATION pi;
   // set the size of the structures
   ZeroMemory( &si, sizeof(si) );
   si.cb = sizeof(si);
   ZeroMemory( &pi, sizeof(pi) );
  // start the program up
  CreateProcess( lpApplicationName,   // the path
    "",             // 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
    ;
    // Close process and thread handles.
    CloseHandle( pi.hProcess );
    CloseHandle( pi.hThread );
}

我认为您需要检查为什么它不关闭 - 获取VisualStudio/windbg并连接到未关闭的过程并检查其悬挂的位置。

相关文章: