LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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, 02: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, 03:57 AM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
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



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 11:47 AM
Too many file open - How can we define Max limit of file descriptor janeshb Linux - Server 11 09-29-2009 10:41 AM
open local file error when creating file descriptor hellgirl Linux - Newbie 1 09-14-2009 10:03 PM
Deleted log file - how to get back via file descriptor and keep alive? prollocks Linux - General 1 05-29-2009 09:08 AM
apt-file returns nothing; 'bad file descriptor' overbored Debian 3 10-03-2004 09:13 PM

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

All times are GMT -5. The time now is 02:03 PM.

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
Open Source Consulting | Domain Registration