'How to store file descriptor in a struct
I have a program which spawns multiple children. The number of children spawned is unknown as it relies on user input. Every child and parent must have two pipes connecting to them. However, I want to access the file descriptors of the pipes to be able to read and write to the specific child using the pipes in future functions. I have looked into making the file descriptor as fd[i][2], i being the specific child that pipe is referring to. I am aware I will have to dynamically allocate the file descriptors as the array is increasing in size every time the user creates a new child. I know that every child will have an array being fd[2][2]. My goal is to store the file descriptors in a struct so I can access them in other functions. But I am struggling with how to allocate the memory for the file descriptors. I don't really have code to show as it is more of a knowledge-based question.
What I have is a struct:
typedef struct {
int* fd[2][2];
}FileDesc;
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
