I already looked at the only similar message I could find, but this is not what I was looking for.
Basically, I'm trying to start Odd-Even Sort using forking, so the child has odds and the parent works with alignment. They require the sharing of vector input values, as well as Boolean sorts.
The following code, without any unsuccessful attempts at memory exchange, is just the basic basis for using forks with a search algorithm:
while(!sorted) { pID = fork(); sorted = true; cout << "Sort set to TRUE." << endl; if(pID == 0) { int num = 1; cout << "Child swap run" << endl; Swap((void *) num); cout << "Status: " << ((sorted) ? "SORTED" : "UNSORTED") << endl; exit(0); } else if(pID < 0) { cout << "Failed to fork." << endl; exit(1); } else { wpid = waitpid(pID, &status, waitStatus); int num = 0; cout << "Parent swap run" << endl; Swap((void *) num); cout << "Status: " << ((sorted) ? "SORTED" : "UNSORTED") << endl; } }
I tried several ways to hack this memory exchange, but I can not find a single resource that really explains how it works, what I need and the best way to do it.
So my requirements are as follows:
- Parent and child must be able to share global vector and logical
- It should be possible to execute in a loop as shown
- This should work with variables that are used in main () and in the swap () function
If you have any advice, I will be very grateful to them. Thanks!
Befall
source share