Can anybody give me a concise meaning of a file descriptor

tpat
tpat used Ask the Experts™
on
Can anybody give me a concise meaning of a file descriptor ?

Thanks
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
An integer that identifies an open file within a process

.Dave
File descriptors are an 'object' that certain functions use to work with files. If you are familiar with using file streams (fopen, fread, fprintf, fclose & FILE*), you can think of file descriptors as similar in purpose to the FILE structure. The file stream functions (fopen, etc) use the FILE structure to keep track of info useful for manipulating a file. File descriptors help certain file manipulation functions (open, read, close) keep track of file info.

If I remember correctly, a file descriptor is basically just an integer. I imagine that it is an index into a table somewhere.

So, someone suggesting that you use file descriptors to do directory manipulation wasn't being terribly helpful. They were basically saying, use some file manipulation functions to do your directory stuff.

I can't give you explicit help, but hopefully can point you down the path. Your compiler probably has some directory manipulation functions in it's libraries. In UNIX/Linux, I remember using functions like 'opendir', 'readdir', etc to work with directories. In MS Visual Studio, I didn't find these functions but classes like DirectoryInfo, etc.

You'll need to search thru your compiler's docs to figure out what it provides.
Commented:
Linux/Unix uses a per process table called "File Descriptor Table".
"File Descriptor" is an index from this table.
When a file is opened, the smallest index from this table is returned.
And there is one more table called File Table, which is global.
When a process opens a file or creates a file, the operating system allots an entry from each of these tables. This inturn will be pointing to an entry in the Inode Table.
All these tables together maintain the file state and also user's access permissions.

Commented:
You can refer to this page for a detailed information on physical file structure: http://www.hicom.net/~shchuang/Unix/unix4.html

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial