Do different threads within a single process have distinct independent file descriptor tables? If multiple threads within the same process concurrently access a single file, will the offset into the file for two different calls to open
performed by different threads be thread-specific?
The file descriptors are shared between the threads. If you want "thread specific" offsets, why not have each thread use a different file descriptor ( open(2) multiple times) ?
Any system level (syscall) file descriptor access is thread safe in all mainstream UNIX-like OSes.
A file descriptor is a number that uniquely identifies an open file in a computer's operating system. It describes a data resource, and how that resource may be accessed. When a program asks to open a file — or another data resource, like a network socket — the kernel: Grants access.
A file descriptor is an unsigned integer used by a process to identify an open file. The number of file descriptors available to a process is limited by the /OPEN_MAX control in the sys/limits. h file. The number of file descriptors is also controlled by the ulimit -n flag.
No, there is only one file descriptor table per process, and it's shared among all the threads.
From your problem description, you might want to look into the pread() and pwrite() functions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With