There is a file socket descriptor (socketpair or pipe - no difference). It is required that it be blocked on read()
in one process, but not in the other (that is, if there is no data, read()
returns -1 and errno == EAGAIN
).
The fact is that
int newfd = dup(oldfd); fcntl (newfd, F_SETFL, fcntl(newfd,F_GETFL)|O_NONBLOCK);
Makes both descriptors unblockable . Calling fcntl()
before fork()
or after does not change the situation.
Similar behavior for both tty and regular file. It's easier with them (you can independently rediscover, for example, / dev / tty), but I'm interested in the socket (or pipe).
What are some ideas?
If you think that this is impossible in principle, also respond.
Perhaps the following information will be helpful:
Each file has its own flags, it has been flagged by open (2) and it can be modified by fcntl (). Duplicated file descriptors (made with dup (2), fcntl (F_DUPFD), fork (2), etc.).
IMHO from this it follows that I need somehow ( that's the point of the question ) to get a handle to a new record in the file table, referring to the same data queues as the specified socket.
PS
No doubt, but checked. execl() (system())
not affected.