divinelemon
divinelemon

Reputation: 2097

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?

Upvotes: 0

Views: 208

Answers (1)

David Grayson
David Grayson

Reputation: 87396

For Linux, the strace utility is the answer (as mentioned by Peter in a comment). 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. You should focus on the open calls.

Upvotes: 2

Related Questions