• C

C Programming: Working with OPEN(2) and File Descriptors

After reading about OPEN(2), I am still confused about the returned value.


It says that the returned value is a File Descriptor, but I tried googling it, and cannot find much about file descriptors, and how to use them.

I have a project that requires me to work with file descriptors, and I would like to learn more about their built-in functions.

Can you please provide a examples of working with "fd" after using the OPEN command?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

man 2 close
man 2 dup
man 2 read
man 2 write
man 2 lseek
man 2 fstat
man 2 select
man 2 fcntl
mccarlIT Business Systems Analyst / Software DeveloperCommented:
File Descriptors are just indexes into tables of data kept within the runtime/operating system that represents the file that you have opened. You can't DO anything with them, except to pass them back to other functions (as listed by "ozo") to actually operate on the file that you have opened.

They have no inherit meaning. Think of them like "pointers" (if you know what C/C++ pointers are all about) in that the actual value of the pointer is not of much use. You are only concern with the data at the memory location where the pointer points to. File descriptors are similar, you don't care about the actual value just what open file they point to.

I have a project that requires me to work with file descriptors
If you can elaborate a little more on exactly what this project is required to do, we may be able to provide some more specific advice.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
pzozulkaAuthor Commented:
Thanks to both of you. mccarl, your explanation is extremely clear, so no further advice is needed. I'm sure I'll be posting more questions about this project soon.
mccarlIT Business Systems Analyst / Software DeveloperCommented:
Not a problem, glad to help!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.