From 302190f9f704381475daed4c870ee2cd54a2392c Mon Sep 17 00:00:00 2001 From: Dmitrii Pichulin Date: Thu, 31 Mar 2016 13:48:04 +0400 Subject: [PATCH] #4 added ability to close unnecessary conhost.exe --- src/php-cgi-spawner.c | 42 ++++++++++++++++++++++++++++++++++++++++++ src/php-cgi-spawner.rc | 2 +- 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/src/php-cgi-spawner.c b/src/php-cgi-spawner.c index 2171aef..474d68b 100644 --- a/src/php-cgi-spawner.c +++ b/src/php-cgi-spawner.c @@ -1,4 +1,5 @@ #include +#include #pragma comment( lib, "kernel32.lib") #pragma comment( lib, "ws2_32.lib") @@ -94,6 +95,47 @@ __forceinline void spawner( char * app, unsigned port, unsigned cgis, &si, &pi ) ) return; + // close unnecessary conhost.exe + // (https://github.com/deemru/php-cgi-spawner/issues/4) + if( ( restart_delay >= 100 && restart_delay <= 200 ) || + ( restart_delay >= 1100 && restart_delay <= 1200 ) ) + { + PROCESSENTRY32 pe32; + HANDLE hSnap; + + Sleep( restart_delay ); + hSnap = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, + pi.dwProcessId ); + pe32.dwSize = sizeof( pe32 ); + + if( hSnap != INVALID_HANDLE_VALUE ) + { + if( Process32First( hSnap, &pe32 ) ) + do + { + if( pe32.th32ParentProcessID == pi.dwProcessId ) + { + HANDLE hCon; + + hCon = OpenProcess( PROCESS_TERMINATE, 0, + pe32.th32ProcessID ); + + if( hCon != INVALID_HANDLE_VALUE ) + { + TerminateProcess( hCon, + CONTROL_C_EXIT ); + CloseHandle( hCon ); + } + + break; + } + } + while( Process32Next( hSnap, &pe32 ) ); + + CloseHandle( hSnap ); + } + } + CloseHandle( pi.hThread ); hProcesses[i] = pi.hProcess; } diff --git a/src/php-cgi-spawner.rc b/src/php-cgi-spawner.rc index af37481..19f8693 100644 --- a/src/php-cgi-spawner.rc +++ b/src/php-cgi-spawner.rc @@ -2,7 +2,7 @@ 2 ICON "php-cgi-spawner.ico" -#define PCS_VERSION 1,15,12,17 +#define PCS_VERSION 1,16,03,31 #define PCS_VERSION_STR "8K\0" VS_VERSION_INFO VERSIONINFO