I wanted to simulate preemptive by running two process simultaneously. Let's say that I have program A which runs
while(1){
printf("A\n");
}
and program B which runs
while(1){
printf("B\n");
}
What I wanted to do is for the program to display (or at least simulate) how preemptive works, so I want the .exe to look more or less like this
A
A
A
B
B
A
A
...
Here is how my code so far
#include <windows.h>
#include <stdio.h>
#include <tchar.h>
void _tmain( int argc, TCHAR *argv[] ){
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) );
if(CreateProcess
(TEXT("c:\\C\\Osenshuu\\create_process_a.exe"),
NULL,
NULL,
NULL,
FALSE,
0,
NULL,
NULL,
&si,
&pi)){
WaitForSingleObject(pi.hProcess,INFINITE);
CloseHandle(pi.hThread);
CloseHandle(pi.hProcess);
}
else{
printf("The process could not be started...");
}
}
It works great displaying the A program but now I'm wondering how could I add b.exe to that createprocess to make both program A and B run simultaneously? Is it even possible to do it?