Skip to content

Commit

Permalink
#4 added ability to close unnecessary conhost.exe
Browse files Browse the repository at this point in the history
  • Loading branch information
deemru committed Mar 31, 2016
1 parent 93f8888 commit 302190f
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
42 changes: 42 additions & 0 deletions src/php-cgi-spawner.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <winsock.h>
#include <TlHelp32.h>

#pragma comment( lib, "kernel32.lib")
#pragma comment( lib, "ws2_32.lib")
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/php-cgi-spawner.rc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 302190f

Please sign in to comment.