• 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?
mccarlConnect With a Mentor IT 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.
ozoConnect With a Mentor Commented:
man 2 close
man 2 dup
man 2 read
man 2 write
man 2 lseek
man 2 fstat
man 2 select
man 2 fcntl
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!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.