LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-23-2010, 03:47 AM   #1
avee137
Member
 
Registered: Apr 2010
Location: bangalore,india
Distribution: ubuntu 9.10,CentOS 5
Posts: 120

Rep: Reputation: 16
file descriptor doubt.


please consider the following code:
unsigned long word;
Code:
ssize_t nr;
/* read a couple bytes into 'word' from 'fd' */
nr = read (fd, &word, sizeof (unsigned long));
if (nr == -1)
/* error */
This example reads from the file descriptor fd into word.

what does it mean when we say-"reads from the file descriptor".?
All i understand about file descriptor is that its an int value returned by open()system call.Hence the doubt:if fd is not a pointer or an address whats the meaning of saying from file descriptor.

Any relevant help would be appreciated.
 
Old 08-23-2010, 04:57 AM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,417

Rep: Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397
I/O channels are numbered as integers.
Consider the std login env

Code:
name = num
-----------

stdin = 0
stdout = 1
stderr = 2
See man page for open
Quote:
Given a pathname for a file, open() returns a file descriptor, a small,non-negative integer for use in subsequent system calls (read(2), write(2), lseek(2), fcntl(2), etc.). The file descriptor returned by a successful call will be the lowest-numbered file descriptor not currently open for the process.
By comparison, see the man pages for fopen() & fdopen().
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Get the absolute path of file using file descriptor. appas Programming 7 01-19-2012 12:47 PM
Too many file open - How can we define Max limit of file descriptor janeshb Linux - Server 11 09-29-2009 11:41 AM
open local file error when creating file descriptor hellgirl Linux - Newbie 1 09-14-2009 11:03 PM
Deleted log file - how to get back via file descriptor and keep alive? prollocks Linux - General 1 05-29-2009 10:08 AM
apt-file returns nothing; 'bad file descriptor' overbored Debian 3 10-03-2004 10:13 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:01 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration