29 int main(
int argc, 
const char** argv )
 
   32   HANDLE shutdown_event;
 
   33   char safe_process_name[32]= {0};
 
   34   int retry_open_event= 2;
 
   36   signal(SIGINT,   SIG_IGN);
 
   37   signal(SIGBREAK, SIG_IGN);
 
   38   signal(SIGTERM,  SIG_IGN);
 
   41     fprintf(stderr, 
"safe_kill <pid>\n");
 
   46   _snprintf(safe_process_name, 
sizeof(safe_process_name),
 
   47             "safe_process[%d]", pid);
 
   50   while ((shutdown_event=
 
   51           OpenEvent(EVENT_MODIFY_STATE, FALSE, safe_process_name)) == NULL)
 
   59     process= OpenProcess(SYNCHRONIZE| PROCESS_QUERY_INFORMATION, FALSE, pid);
 
   66     if (!GetExitCodeProcess(process,&exit_code))
 
   68        fprintf(stderr,  
"GetExitCodeProcess failed, pid= %d, err= %d\n",
 
   73     if (exit_code != STILL_ACTIVE)
 
   82     if (retry_open_event--)
 
   86       fprintf(stderr, 
"Failed to open shutdown_event '%s', error: %d\n",
 
   87               safe_process_name, GetLastError());
 
   92   if(SetEvent(shutdown_event) == 0)
 
   94     fprintf(stderr, 
"Failed to signal shutdown_event '%s', error: %d\n",
 
   95             safe_process_name, GetLastError());
 
   96     CloseHandle(shutdown_event);
 
   99   CloseHandle(shutdown_event);