#include <windows.h>
#include <stdio.h>
int main(void) {
int retCode = 0;
PROCESS_INFORMATION pi; /* filled in by CreateProcess */
STARTUPINFO si; /* startup info for the new process */
/* print out our process ID */
printf("Process %d reporting for duty\n",GetCurrentProcessId());
/* Get startup info for current process, we will use this
as the startup info for the new process as well... */
GetStartupInfo(&si);
/* Call CreateProcess, telling it to run DivideByZero
with lots of defaults... (the NULLs mean "use defaults")
*/
CreateProcess(NULL, /* lpApplicationName */
"DivideByZero.exe", /* lpCommandLine */
NULL, /* lpsaProcess */
NULL, /* lpsaThread */
FALSE, /* bInheritHandles */
DETACHED_PROCESS, /* dwCreationFlags */
NULL, /* lpEnvironment */
NULL, /* lpCurDir */
&si, /* lpStartupInfo */
&pi /* lpProcInfo */
);
printf("New Process ID: %d\n",pi.dwProcessId);
getc(stdin); //Pause here to check task manager etc...
retCode = ExitProcess(pi.dwProcessId);
printf("Returned %d\n\n",retCode);
return(0);
}
//DivideByZero
#include <stdio.h>
int main(void)
{
int result = 0;
printf("DivideByZero is about to crash\n");
result = 42/result;
printf("Result: %d\n", result);
return(0);
}