open()如果我打开同一文件两次会怎样? [英] open() what happens if I open twice the same file?

查看:523
本文介绍了open()如果我打开同一文件两次会怎样?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我打开同一文件两次,它会给出错误消息,还是会创建两个不同的文件描述符?例如

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);

推荐答案

在这种情况下,由于您将两个文件都以只读方式打开,因此您将获得两个引用同一文件的不同文件描述符.有关更多详细信息,请参见打开手册页.

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.

这篇关于open()如果我打开同一文件两次会怎样?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆