Skip to content

Instantly share code, notes, and snippets.

@figengungor
Created October 8, 2013 15:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save figengungor/6886684 to your computer and use it in GitHub Desktop.
Save figengungor/6886684 to your computer and use it in GitHub Desktop.
Parent Process in Windows Lab 2 -- creates a process that creates threads
#include <stdio.h>
#include <Windows.h>
define NO_OF_PROCESS=1;
int main(int argc, char* argv[])
{
STARTUPINFO si[NO_OF_PROCESS];
PROCESS_INFORMATION pi[NO_OF_PROCESS];
HANDLE handles[NO_OF_PROCESS];
char *lpCommandLine = {"child.exe 5"}; //child.exe should create 5 threads
int i=0;
for(i=0; i<NO_OF_PROCESS; i++)
{
SecureZeroMemory(&si[i], sizeof(STARTUPINFO));
si[i].cb = sizeof(STARTUPINFO);
SecureZeroMemory(&pi[i], sizeof(PROCESS_INFORMATION));
if(!CreateProcess(NULL, lpCommandLine[i], NULL, FALSE, NULL, NULL, &si[i], &pi[i])))
{
printf("new process couldn't be created");
system("pause");
exit(0);
}
else
{
printf("parent is working");
handle[i] = pi.hProcess;
}
}
WaitForSingleObject(handle[0],INIFINITE); //parent waits for one process(child.exe)
for(i=0; i<NO_OF_PROCESS, i++)
{
CloseHandle(pi[i].hProcess);
CloseHandle(pi[i].hThread);
}
return 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment