A file descriptor is a small int value that allows you to access the file. This is the index to the file descriptor table, the data structure in the kernel associated with each individual process. A process cannot do anything meaningful in a file descriptor from another process because it does not have access to any other process file descriptor table.
This is due to basic security considerations. If one process could perform operations on an open file belonging to another process, chaos would arise. In addition, the file descriptor simply does not contain enough information to do what you are trying to do; one process file descriptor 0 (stdin) can refer to a completely different file than another process file descriptor 0. And even if they are the same file, each process must maintain its own information about the state of this open file (how much it read / wrote, etc.).
If you describe what you are trying to accomplish, perhaps we can help.
EDIT:
You want to transfer data from one program to another. The easiest way to do this is to create a channel ( man 2 pipe ). Note that the second process must be a child of the first.
An alternative could be to create a file that the second process can open and read (not try to exchange a file descriptor), or you can use sockets.
source share