Search code examples
cfile-descriptor

open() what happens if I open twice the same file?


If I open the same file twice, will it give an error, or will it create two different file descriptors? For example

a = open("teste.txt", O_RDONLY);
b = open("teste.txt", O_RDONLY);

Solution

  • In this case, since you're opening both files as read-only, you will get two different file descriptors that refer to the same file. See the man page for open for more details.