#include <stdio.h>
#include <stdlib.h>
#include <windows.h>

main(
    int argc,
    char *argv[]
){
    DWORD   dwPid = atoi(argv[1]) ;
    HANDLE  hProcess ;
    DWORD   dwStatus ;

    hProcess = OpenProcess(PROCESS_TERMINATE|SYNCHRONIZE,FALSE,dwPid) ;
    if (hProcess != NULL)  {
        if (TerminateProcess(hProcess,argc > 2 ? atoi(argv[2]) : 2))  {
            printf("Waiting 10S for termination...\n") ;
            dwStatus = WaitForSingleObject(hProcess,INFINITE) ;
            switch (dwStatus)  {
                case WAIT_OBJECT_0:  {
                    printf("Process terminated.\n") ;
                    break ;
                }
                case WAIT_TIMEOUT:  {
                    printf("Timed out.\n") ;
                    break ;
                }
                default:  {
                    printf("WaitForSingleObject error %lu\n",GetLastError()) ;
                    break ;
                }
            }
        }
        else  {
            printf("TerminateProcess error %lu\n",GetLastError()) ;
        }
    }
    else  {
        printf("OpenProcess error %lu\n",GetLastError()) ;
    }
    return(0) ;
}
