Is there any way to access the file descriptor of a file opened in c++? So ...
#include <iostream>
#include <fstream>
using namespace std;
int main() {
ifstream inputFile( "file.txt",ios::in );
cout << inputFile.fileDesc << endl;//made up call
return 0;
}
The question is, does something like fileDesc exist for ifstreams? If not how would I go about doing this?
In the /proc pseudo filesystem, we can find the open file descriptors under /proc/<pid>/fd/ where <pid> is the PID of a given process. Thus, we have to determine the process identification number (PID) of a process to look at its open file descriptors.
A file descriptor is a number that uniquely identifies an open file in a computer's operating system. It describes a data resource, and how that resource may be accessed. When a program asks to open a file — or another data resource, like a network socket — the kernel: Grants access.
Use the ulimit -n command to view the number of file descriptors configured for your Linux system.
If you're trying to get to the FILE* from the stream then the answer is basically "you can't" as stated by more enlightened people than me here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With