Created
October 8, 2013 15:39
-
-
Save figengungor/6886684 to your computer and use it in GitHub Desktop.
Parent Process in Windows Lab 2 -- creates a process that creates threads
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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