Home > Blockchain >  Check what files a program reads from a computer (C )
Check what files a program reads from a computer (C )

Time:12-15

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?

CodePudding user response:

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.

  • Related