Advertisement
Guest User

Parent and child process

a guest
Feb 20th, 2020
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. \\Parent process(В 1 проекте)
  2. #include <stdio.h>
  3. #include <windows.h>
  4. #include <ctime>
  5.  
  6.  
  7.  
  8. int main()
  9. {
  10. STARTUPINFO StartupInfo;
  11. PROCESS_INFORMATION ProcInfo;
  12. TCHAR TXT[] = TEXT("D:\\Visual Studio\\4\\lab 1\\Debug\\Child.exe");
  13.  
  14. ZeroMemory(&StartupInfo, sizeof(StartupInfo));
  15. StartupInfo.cb = sizeof(StartupInfo);
  16. ZeroMemory(&ProcInfo, sizeof(ProcInfo));
  17.  
  18. printf("Parent process was run.\n");
  19.  
  20. time_t seconds = time(NULL);
  21. tm* timeinfo = localtime(&seconds);
  22. printf("Current Datetime:%s", asctime(timeinfo));
  23.  
  24. Sleep(10000);
  25.  
  26. if (!CreateProcess(TXT,
  27. NULL,
  28. NULL,
  29. NULL,
  30. FALSE,
  31. CREATE_NEW_CONSOLE,
  32. NULL,
  33. NULL,
  34. &StartupInfo,
  35. &ProcInfo)
  36. )
  37.  
  38. printf("CreateProcess failed.\n");
  39.  
  40.  
  41. WaitForSingleObject(ProcInfo.hProcess, INFINITE);
  42.  
  43. printf("End of child process.\n");
  44.  
  45. Sleep(10000);
  46.  
  47.  
  48. CloseHandle(ProcInfo.hProcess);
  49. CloseHandle(ProcInfo.hThread);
  50.  
  51. }
  52.  
  53. \\Child process(2 проект)
  54. #include <windows.h>
  55. #include <stdio.h>
  56. #include <ctime>
  57.  
  58.  
  59.  
  60. int main()
  61. {
  62. printf("Child process was run.\n");
  63. time_t seconds = time(NULL);
  64. tm* timeinfo = localtime(&seconds);
  65. printf("Current Datetime:%s", asctime(timeinfo));
  66. system("pause");
  67. return 0;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement