When a child process reads in a file, will there be an offset of the same file in the parent process?
Yes, since the offset is stored in the system file table. You can get a similar effect using dup
or dup2
.
If 1 is true, is there a convenient way for two processes to get the same effect from fork
in the same file? This means that two processes use location (offset) information in the same file.
There is a method called “file descriptor transfer” using Unix domain sockets. Find the "helper" data in sendmsg
.
Is there a way to unlock so that both processes have completely unrelated tables, for example two unrelated processes, they just opened the same files.
To do this, you need to open
save the file. Although it does not do what you want, you should also look for the FD_CLOEXEC
flag.
source share