Xom9ik

Lab_3/15var (IV semester) OS&SP

Apr 17th, 2018
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.94 KB | None | 0 0
  1. //child.exe
  2. #include "stdafx.h"
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <iostream>
  6.  
  7. int main(int argc, char *argv[])
  8. {
  9.     std::cout << "------------------------" << std::endl;
  10.     std::cout << "Child started" << std::endl;
  11.     char *USERNAME = getenv("USERNAME");
  12.     char *COMPUTERNAME = getenv("COMPUTERNAME");
  13.     char *MYPATH = getenv("MYPATH");
  14.     std::cout << "USERNAME: " << USERNAME << std::endl;
  15.     std::cout << "COMPUTERNAME: " << COMPUTERNAME << std::endl;
  16.     std::cout << "MYPATH: " << MYPATH << std::endl;
  17.     system("pause");
  18.     std::cout << "Child destroyed" << std::endl;
  19.     std::cout << "------------------------" << std::endl;
  20.     return 0;
  21. }
  22.  
  23. //parent_3_1.exe
  24. #include "stdafx.h"
  25. #include <stdio.h>
  26. #include <stdlib.h>
  27. #include <iostream>
  28. #include <process.h>
  29.  
  30. void main(int argc, char *argv[])
  31. {
  32.     std::cout << "Parent_3_1 started" << std::endl;
  33.     putenv("MYPATH=D:\\TEMP");
  34.     std::cout << "Parent_3_1 call <spawnle(int mode, char *fname, char *arg0, ..., char *argN, NULL, char *envp[ ])> child.exe" << std::endl;
  35.     if (spawnle(P_WAIT, "child.exe", argv[0], NULL, NULL, _environ) == -1)
  36.         std::cout << "Error: " << errno << std::endl;
  37.     else
  38.         std::cout << "All is well" << std::endl;
  39.     std::cout << "Parent_3_1 destroyed" << std::endl;
  40.     system("pause");
  41. }
  42.  
  43. //parent_3_2.exe
  44. #include "stdafx.h"
  45. #include <stdio.h>
  46. #include <stdlib.h>
  47. #include <iostream>
  48. #include <process.h>
  49.  
  50. void main(int argc, char *argv[])
  51. {
  52.     std::cout << "Parent_3_2 started" << std::endl;
  53.     putenv("USERNAME=PARENT_2");
  54.     putenv("COMPUTERNAME=OS-LAB-3");
  55.     putenv("MYPATH=D:\\TEMP");
  56.     std::cout << "Parent_3_2 call <spawnle(int mode, char *fname, char *arg0, ..., char *argN, NULL, char *envp[ ])> child.exe" << std::endl;
  57.     if (spawnle(P_WAIT, "child.exe", argv[0], NULL, NULL, _environ) == -1)
  58.         std::cout << "Error: " << errno << std::endl;
  59.     else
  60.         std::cout << "All is well" << std::endl;
  61.     std::cout << "Parent_3_2 destroyed" << std::endl;
  62.     system("pause");
  63. }
Advertisement
Add Comment
Please, Sign In to add comment