I am currently trying to pass a std::queue<std::pair<KInstruction*, int>>
variable from child to parent process.
However, the data that parent process does not correct. All of the std::pair
that in the queue that parent received looks like NULL, [some random int]
, but it is supposed to be some address, 1 or -1 or 0
.
Here is what I do.
extern::queue<std::pair<KInstruction*, int>> queue;
std::queue<std::pair<KInstruction*, int>> tmp;
if (pid == 0) {
...
compute queue
...
tmp = queue
close(fd[P1_READ]);
close(fd[P1_WRITE]);
// tmp is the queue variable
if (write(fd[P2_WRITE], &tmp, sizeof(tmp)) < 0) {
perror("Child: Failed to write response value");
exit(EXIT_FAILURE);
}
close(fd[P2_READ]);
close(fd[P2_WRITE]);
} else {
wait(NULL);
close(fd[P2_READ]);
close(fd[P2_WRITE]);
read(fd[P1_READ], &tmp, sizeof(tmp));
close(fd[P1_READ]);
close(fd[P1_WRITE]);
}
The queue's size that parent receive is correct. But all the data is wrong.
What I actually trying to do is to let parent process use the queue that child process compute. If anyone has better solution is appreciated.