Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //child.exe
- #include "stdafx.h"
- #include <stdio.h>
- #include <stdlib.h>
- #include <iostream>
- int main(int argc, char *argv[])
- {
- std::cout << "Child started" << std::endl;
- std::cout << "Count arguments: " << argc << std::endl;
- std::cout << "Arguments:" << std::endl;
- for (int i = 0; i < argc; i++) {
- std::cout << i+1 << ") " << argv[i] << std::endl;
- }
- system("pause");
- std::cout << "Child destroyed" << std::endl;
- return 0;
- }
- //parent_1_1.exe
- #include "stdafx.h"
- #include <stdio.h>
- #include <stdlib.h>
- #include <iostream>
- #include <process.h>
- #include <time.h>
- void main()
- {
- std::cout << "Parent_1_1 started" << std::endl;
- time_t rawtime;
- struct tm * timeinfo;
- time(&rawtime);
- timeinfo = localtime(&rawtime);
- std::cout << "Parent_1_1 call <execl(char *fname, char *arg0, ..., char *argN, NULL)> child.exe" << std::endl;
- if (execl("child.exe", "Parent_1_1", "username", "password", "email", asctime(timeinfo), NULL) == -1)
- std::cout << "Error: " << errno << std::endl;
- else
- std::cout << "All is well" << std::endl;
- }
- //parent_1_2.exe
- #include "stdafx.h"
- #include <stdio.h>
- #include <stdlib.h>
- #include <iostream>
- #include <process.h>
- #include <time.h>
- void main()
- {
- std::cout << "Parent_1_2 started" << std::endl;
- time_t rawtime;
- struct tm * timeinfo;
- time(&rawtime);
- timeinfo = localtime(&rawtime);
- std::cout << "Parent_1_2 call <spawnl(int mode, char *fname, char *arg0, ..., char *argN, NULL)> child.exe" << std::endl;
- if (spawnl(P_WAIT, "child.exe", "Parent_1_2", "username", "password", "email", asctime(timeinfo), NULL) == -1)
- std::cout << "Error: " << errno << std::endl;
- else
- std::cout << "All is well" << std::endl;
- std::cout << "Parent_1_2 destroyed" << std::endl;
- system("pause");
- }
- //parent_2_1.exe
- #include "stdafx.h"
- #include <stdio.h>
- #include <stdlib.h>
- #include <iostream>
- #include <process.h>
- #include <time.h>
- #include <vector>
- void main()
- {
- std::cout << "Parent_2_1 started" << std::endl;
- time_t rawtime;
- struct tm * timeinfo;
- time(&rawtime);
- timeinfo = localtime(&rawtime);
- std::vector<char*> commandVector;
- commandVector.push_back(const_cast<char*>("child.exe"));
- commandVector.push_back(const_cast<char*>("Parent_2_1"));
- commandVector.push_back(const_cast<char*>("username"));
- commandVector.push_back(const_cast<char*>("password"));
- commandVector.push_back(const_cast<char*>("email"));
- commandVector.push_back(const_cast<char*>(asctime(timeinfo)));
- commandVector.push_back(NULL);
- std::cout << "Parent_2_1 call <execv(char *fname, char *arg[ ])> child.exe" << std::endl;
- if (execv(commandVector[0], &commandVector[0]) == -1)
- std::cout << "Error: " << errno << std::endl;
- else
- std::cout << "All is well" << std::endl;
- std::cout << "Parent_2_1 destroyed" << std::endl;
- system("pause");
- }
- //parent_2_2.exe
- #include "stdafx.h"
- #include <stdio.h>
- #include <stdlib.h>
- #include <iostream>
- #include <process.h>
- #include <time.h>
- #include <vector>
- void main()
- {
- std::cout << "Parent_2_2 started" << std::endl;
- time_t rawtime;
- struct tm * timeinfo;
- time(&rawtime);
- timeinfo = localtime(&rawtime);
- std::vector<char*> commandVector;
- commandVector.push_back(const_cast<char*>("child.exe"));
- commandVector.push_back(const_cast<char*>("Parent_2_2"));
- commandVector.push_back(const_cast<char*>("username"));
- commandVector.push_back(const_cast<char*>("password"));
- commandVector.push_back(const_cast<char*>("email"));
- commandVector.push_back(const_cast<char*>(asctime(timeinfo)));
- std::cout << "Parent_2_2 call <spawnv(int mode, char *fname, char *arg[ ])> child.exe" << std::endl;
- if (spawnv(P_WAIT, commandVector[0], &commandVector[0]) == -1)
- std::cout << "Error: " << errno << std::endl;
- else
- std::cout << "All is well" << std::endl;
- std::cout << "Parent_2_2 destroyed" << std::endl;
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement