如何检查文件是否已被 C++ 中的另一个应用程序打开? [英] How to check if a file has been opened by another application in C++?

查看:15
本文介绍了如何检查文件是否已被 C++ 中的另一个应用程序打开?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道,C++ 中有 is_open() 函数,但我想要一个程序来检查文件是否未被另一个应用程序打开.有没有办法使用标准库来做到这一点?

I know, that there's the is_open() function in C++, but I want one program to check if a file hasn't been opened by another application. Is there any way to do it using standard library?

编辑 - 在答案中澄清这是针对 Linux 应用程序的.

EDIT - Clarified in the answers that this is for a Linux application.

推荐答案

不仅标准库没有这个功能,一般来说也是不可能的.你可以(在 linux 上)检查 /proc/*/fd —但您的程序可能无权对其他用户的进程执行此操作(例如,这是 Ubuntu 中的默认设置).

Not only the standard library does not have this funcionality, it's not even possible in general. You could (on linux) check /proc/*/fd — but it is possible that your program does not have permission to do it on processes from other users (this is the default in Ubuntu, for instance).

这篇关于如何检查文件是否已被 C++ 中的另一个应用程序打开?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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