Difference between file descriptor and file pointer | Unix Linux Forums | UNIX for Dummies Questions & Answers

  Go Back    


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

Difference between file descriptor and file pointer

UNIX for Dummies Questions & Answers


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 03-11-2010
jimmyuk jimmyuk is offline
Registered User
 
Join Date: Mar 2010
Last Activity: 15 April 2010, 2:00 AM EDT
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Difference between file descriptor and file pointer

hi....,
can anyone tell me what is the exact difference between file descriptor and file pointer...... and why file descriptor takes integer value???
Sponsored Links
    #2  
Old 03-11-2010
karthigayan's Avatar
karthigayan karthigayan is offline
Registered User
 
Join Date: Apr 2009
Last Activity: 9 July 2013, 6:35 AM EDT
Location: India , Chennai
Posts: 137
Thanks: 0
Thanked 3 Times in 3 Posts
MySQL

File descriptor is an integer which is an index in the kernel on the opened files(Which is called file descriptor table).It is used to deal with the files . most of the functions like open,close,read using the file descriptors to deal with the files.

File pointer is a location with in the file.Which points the next character which going to read.
Sponsored Links
    #3  
Old 03-11-2010
jlliagre jlliagre is offline Forum Advisor  
ɹǝsn sıɹɐlos
 
Join Date: Dec 2007
Last Activity: 22 August 2014, 1:55 PM EDT
Location: Paris
Posts: 4,406
Thanks: 15
Thanked 461 Times in 417 Posts
While I would mostly agree with the file descriptor definition, a file pointer is not usually what you describe but commonly used to refer to what the standard C library uses to handle files (FILE *).

The associated functions are fopen, fclose, fread, fwrite, fscanf and the likes.
    #4  
Old 03-14-2010
DoxieLvr DoxieLvr is offline
Registered User
 
Join Date: Sep 2009
Last Activity: 4 April 2013, 5:33 PM EDT
Posts: 32
Thanks: 0
Thanked 4 Times in 3 Posts
Quote:
Originally Posted by jlliagre View Post
While I would mostly agree with the file descriptor definition, a file pointer is not usually what you describe but commonly used to refer to what the standard C library uses to handle files (FILE *).

The associated functions are fopen, fclose, fread, fwrite, fscanf and the likes.
I would also note that a file pointer has an associated file descriptor used by the library functions to do the actual I/O calls to the kernel. You can get the associated fd using the fileno function.
Sponsored Links
    #5  
Old 08-13-2010
kvok kvok is offline
Registered User
 
Join Date: Jul 2009
Last Activity: 1 April 2013, 3:23 PM EDT
Posts: 32
Thanks: 3
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by karthigayan View Post
File descriptor is an integer which is an index in the kernel on the opened files(Which is called file descriptor table).It is used to deal with the files . most of the functions like open,close,read using the file descriptors to deal with the files.

File pointer is a location with in the file.Which points the next character which going to read.
So shall I understand that the filedescriptor is number of amount connections for particular process/program which will be used ? and its predefined ?
Sponsored Links
    #6  
Old 08-13-2010
jlliagre jlliagre is offline Forum Advisor  
ɹǝsn sıɹɐlos
 
Join Date: Dec 2007
Last Activity: 22 August 2014, 1:55 PM EDT
Location: Paris
Posts: 4,406
Thanks: 15
Thanked 461 Times in 417 Posts
A file descriptor is an index in a per process table. It isn't predefined outside 0, 1 and 2 which are stdin, stdout and stderr when the process starts.
Sponsored Links
    #7  
Old 08-13-2010
Corona688 Corona688 is online now Forum Staff  
Mead Rotor
 
Join Date: Aug 2005
Last Activity: 22 August 2014, 5:32 PM EDT
Location: Saskatchewan
Posts: 19,236
Thanks: 773
Thanked 3,224 Times in 3,022 Posts
Quote:
Originally Posted by kvok View Post
So shall I understand that the filedescriptor is number of amount connections for particular process/program which will be used ? and its predefined ?
It's not a count of anything, it's just an arbitrary number assigned to that process when it opens a file. The kernel will recognize that number when you make a read() or write() call with it and respond accordingly.

By tradition, certain file numbers are expected to be open by default. stdin should be connected to some sort of input like keyboard or file, stdout should be connected to some sort of output like a screen or file, and stderr should either be connected to a terminal or to nothing. But this is just by tradition. The kernel really doesn't care.

A file pointer is what you get when you open a file with the stdio library. It's a structure that holds buffers and so forth, things that raw file descriptors don't have, but at the heart stdio still uses fd's, at least on UNIX sysems:
Code:
FILE *fp=fopen("filename", "r");
if(fp != NULL)
{
        printf("fp's descriptor is %d\n", fileno(fp));
}

Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
File Descriptor rimser9 Shell Programming and Scripting 3 08-14-2008 06:34 AM
Get the file descriptor of a socket file. C vs Python. goon12 Programming 2 06-11-2008 04:49 PM
confusion (file pointer and file descripter) johnray31 UNIX for Dummies Questions & Answers 1 08-16-2006 03:59 AM
file activity (open/closed) file descriptor info using KORN shell scripting Gary Dunn UNIX for Dummies Questions & Answers 3 06-07-2004 01:54 PM
bad file descriptor? ftb UNIX for Dummies Questions & Answers 1 02-20-2002 06:19 PM



All times are GMT -4. The time now is 05:36 PM.