
Добавил:
Yanus
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:lab7_parent
.cpp#include "windows.h"
#include <stdio.h>
int main()
{
DWORD CreationFlags;
DWORD rc;
STARTUPINFO si;
PROCESS_INFORMATION pi;
printf("Demonstration processes, Main Proccess\n");
memset(&si, 0, sizeof(STARTUPINFO)); si.cb=sizeof(si);
CreationFlags = NORMAL_PRIORITY_CLASS;
char *comLine = "child.exe Ella";
rc=CreateProcess(NULL, comLine, NULL, NULL, FALSE,CreationFlags, NULL, NULL, &si, &pi);
if (!rc)
{
printf("Error create Process, codeError = %ld\n", GetLastError());
getchar();
return 0;
}
printf("For Child Process:\n");
printf("hProcess=%d hThread=%d ProcessId=%ld ThreadId=%ld\n",
pi.hProcess, pi.hThread, pi.dwProcessId, pi.dwThreadId);
char message[] = "I am Parent... (step number %d) \n";
for (int k=0; k<15; k++)
{
if (k == 7)
{
printf("Im killing my child Ella with id = %d\n", pi.hProcess);
TerminateProcess(pi.hProcess, 0);
strcpy(message, "I was Parent... (step number %d)\n");
continue;
}
printf(message, k);
Sleep(1200);
}
return 0;
}
Соседние файлы в предмете Операционные системы