'How to exchange information between 1 parent process and 3 child processes with fork() on c or c++
i need to make a program that can exchange the information between 1 parent and 3 child process created with fork(). The overall task is to send anything from 3-rd child process to 2-nd child and a parent one, and from 2-nd child process to 3-rd. i have the following code to create multiple child processes, but don't understand how to send anything to different processes. Can you help me with this?
for (int kid = 0; kid < 3; ++kid) {
int pid = fork();
if(pid < 0){
exit(EXIT_FAILURE);
}
else if (pid > 0){
/* Parent process */
}
else{
/* Child process */
exit(EXIT_SUCCESS);
}
}
for (int kid = 0; kid < 3; ++kid) {
int status;
pid_t pid = wait(&status); // kids could be ready in any order
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
