Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Access File Descriptor of Open File

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?

like image 277
Dan Snyder Avatar asked Aug 18 '10 14:08

Dan Snyder


People also ask

How do I find open file descriptors?

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.

What is open file descriptor?

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.

How do I find file descriptor number?

Use the ulimit -n command to view the number of file descriptors configured for your Linux system.


1 Answers

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.

like image 120
celavek Avatar answered Sep 24 '22 23:09

celavek