Suppose I have a process A and process B, in which A acts as TCP client, B acts as a TCP server, and A has connected to B, the file descriptor of socket in A is fd1(A), and the file descriptor in B is fd2, at this point, process A forked a child process named C, C also has the fd1(C), which points to the same file table as fd1(A), now B writes some thing to fd2, and which process, A or C, will get the message? Will the message be delivered to fd1(A)? or fd1(C)? or randomly? Thank you.
Share
The message will go to whichever process reads it first. If A executes
read()orrecv()while C is busy doing something else, A will get the data, and vice versa. If both A and C executeread()orrecv()at the same time, the result is undefined.