简体   繁体   English

检查程序从计算机读取的文件 (C++)

[英]Check what files a program reads from a computer (C++)

I have a program that reads files (given to it by the user) from the computer and performs operations on these files.我有一个程序可以从计算机读取文件(由用户提供)并对这些文件执行操作。 However, the program isn't working.但是,该程序不起作用。 I input a valid file with a valid path and the program says it is reading this valid file, however, it doesn't find the files.我输入了一个具有有效路径的有效文件,程序说它正在读取这个有效文件,但是,它没有找到这些文件。 I have verified that the method I use to read the files works.我已经验证了我用来读取文件的方法有效。

So, this prompts my question.所以,这提示了我的问题。 Is it possible for a C++ program to track what files are being read by a specific program, and tell me the path it is trying to read? C++ 程序是否可以跟踪特定程序正在读取哪些文件,并告诉我它试图读取的路径?

For Linux, the strace utility is the answer (as mentioned by Peter in a comment).对于 Linux, strace实用程序就是答案(正如 Peter 在评论中提到的那样)。 You probably have it installed already, so just run strace your_program_name and you can see all the system calls the program is running, and their arguments and return codes.您可能已经安装了它,所以只需运行strace your_program_name ,您就可以看到程序正在运行的所有系统调用,以及它们的 arguments 和返回码。 You should focus on the open calls.您应该专注于open电话。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM