Description:
updated box for windows to prevent error modal dialog
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r131:d5c4e1d8daa2 - - 1 file changed: 3 inserted, 0 deleted

@@ -256,96 +256,99
256 256 int max_mem_usage = 0;
257 257 if(GetProcessMemoryInfo(hProcess, &pmc, sizeof(pmc))) {
258 258 max_mem_usage = pmc.PeakWorkingSetSize;
259 259 if(pmc.PeakPagefileUsage > max_mem_usage)
260 260 max_mem_usage = pmc.PeakPagefileUsage;
261 261 }
262 262 CloseHandle(hProcess);
263 263 if(actual_usage != NULL)
264 264 (*actual_usage) = max_mem_usage;
265 265 return (max_mem_usage <= max_mem);
266 266 }
267 267
268 268 void report_stat(double time_used, int memory_used)
269 269 {
270 270 fprintf(stderr,"%.4lfr%.4lfu%.4lfs%dm\n",
271 271 time_used,
272 272 time_used, (double)0,
273 273 memory_used);
274 274 }
275 275
276 276 double get_process_time_usage(HANDLE hProcess)
277 277 {
278 278 FILETIME creation_time;
279 279 FILETIME exit_time;
280 280 FILETIME kernel_time;
281 281 FILETIME user_time;
282 282 GetProcessTimes(hProcess,
283 283 &creation_time,
284 284 &exit_time,
285 285 &kernel_time,
286 286 &user_time);
287 287
288 288 SYSTEMTIME sys_kernel_time;
289 289 SYSTEMTIME sys_user_time;
290 290 FileTimeToSystemTime(&kernel_time, &sys_kernel_time);
291 291 FileTimeToSystemTime(&user_time, &sys_user_time);
292 292
293 293 double time_used =
294 294 ((sys_kernel_time.wSecond + sys_kernel_time.wMilliseconds/1000.0) +
295 295 (sys_user_time.wSecond + sys_user_time.wMilliseconds/1000.0));
296 296 return time_used;
297 297 }
298 298
299 299 int execute(char *exname, char *inname, char *outname, double t, int max_mem)
300 300 {
301 301 STARTUPINFO si;
302 302 PROCESS_INFORMATION pi;
303 303 int ifsuccess = EXE_RESULT_OK;
304 +
305 + SetErrorMode(SEM_FAILCRITICALERRORS);
306 + SetErrorMode(SEM_NOGPFAULTERRORBOX);
304 307
305 308 ZeroMemory(&si, sizeof(si));
306 309 si.cb = sizeof(si);
307 310 ZeroMemory(&pi, sizeof(pi));
308 311
309 312 setstartupinfo(&si, inname, outname);
310 313
311 314 if(!CreateProcess( NULL, // No module name (use command line).
312 315 TEXT(exname), // Command line.
313 316 NULL, // Process handle not inheritable.
314 317 NULL, // Thread handle not inheritable.
315 318 TRUE, // Set handle inheritance to FALSE.
316 319 0, // No creation flags.
317 320 NULL, // Use parent's environment block.
318 321 NULL, // Use parent's starting directory.
319 322 &si, // Pointer to STARTUPINFO structure.
320 323 &pi)) // Pointer to PROCESS_INFORMATION structure.
321 324 {
322 325 //printf( "CreateProcess failed (%d).\n", GetLastError() );
323 326 fprintf(stderr, "Process creation error.\n");
324 327 report_stat(0,0);
325 328 return EXE_RESULT_ERROR;
326 329 }
327 330 //fprintf(stderr,"Process ID: %ld\n",pi.dwProcessId);
328 331 //fprintf(stderr,"time limit = %d\n",t);
329 332
330 333 // checking memory usage
331 334 // wait 0.1 sec before checking mem usage
332 335
333 336 SetProcessWorkingSetSize(pi.hProcess,
334 337 1,
335 338 max_mem);
336 339 int actual_memory_usage = 0;
337 340
338 341 Sleep(INITIAL_WAIT_FOR_MEM_CHECK);
339 342 if(!check_memory_usage(pi.dwProcessId,max_mem,&actual_memory_usage)) {
340 343 // using too much memory
341 344 fprintf(stderr,"Memory limit exceeded.\n");
342 345 //PrintMemoryInfo(pi.dwProcessId);
343 346 ifsuccess = EXE_RESULT_MEMORY;
344 347 }
345 348
346 349 //printf("PID: %d\n", pi.dwProcessId);
347 350
348 351 if(ifsuccess != EXE_RESULT_MEMORY) {
349 352 int based_time = (int)(t*1000) + 1 - INITIAL_WAIT_FOR_MEM_CHECK;
350 353 bool major_timed_out = (WaitForSingleObject(pi.hProcess,
351 354 based_time)==WAIT_TIMEOUT);
You need to be logged in to leave comments. Login now