TechTalkz.com Logo Ask the Expert

Go Back   TechTalkz.com Technology & Computer Troubleshooting Forums > Tech Support Archives > Linux & Opensource > Unix

Notices

Return value of successful open call

Unix


Reply
 
Thread Tools Display Modes
Old 05-11-2007, 02:29 PM   #1
paresh
Guest
 
Posts: n/a
Return value of successful open call

Return value of successful open call is non negative integer. Thats
mean zero can be file descriptor. Is this a special
file descriptor or zero can be a file descriptor for a regular file.

Can someone highlight on this.

Regards,
Paresh

  Reply With Quote
Old 05-11-2007, 03:31 PM   #2
Stephane CHAZELAS
Guest
 
Posts: n/a
Re: Return value of successful open call

2007-11-05, 09:02(-00), paresh:
> Return value of successful open call is non negative integer. Thats
> mean zero can be file descriptor. Is this a special
> file descriptor or zero can be a file descriptor for a regular file.
>
> Can someone highlight on this.

[...]

By convention, file descriptors 0, 1 and 2 are used as the
default fd to read data from, write data to and write error to
respectively (called stdin, stdout, stderr). Most applications
assume they are already open when you start them, so that it's
generally an error condition for them if they are not.
Applications like getty/xterm/... generally open the 3 of them
to your terminal and shell redirection operators for instance
can reassign them to something else. Functions like scanf, gets,
puts, printf... read from fd 0 and write to fd 1.

But appart from that, they are like any other fds. So for
instance a daemon can use them as any other fds (though you'll
find some tend to open /dev/null on them to avoid side effects
in case they run other commands).

--
Stéphane
  Reply With Quote
Old 05-11-2007, 03:31 PM   #3
paresh
Guest
 
Posts: n/a
Re: Return value of successful open call

On Nov 5, 3:06 pm, Stephane CHAZELAS <this.addr...@is.invalid> wrote:
> 2007-11-05, 09:02(-00), paresh:> Return value of successful open call is non negative integer. Thats
> > mean zero can be file descriptor. Is this a special
> > file descriptor or zero can be a file descriptor for a regular file.

>
> > Can someone highlight on this.

>
> [...]
>
> By convention, file descriptors 0, 1 and 2 are used as the
> default fd to read data from, write data to and write error to
> respectively (called stdin, stdout, stderr). Most applications
> assume they are already open when you start them, so that it's
> generally an error condition for them if they are not.
> Applications like getty/xterm/... generally open the 3 of them
> to your terminal and shell redirection operators for instance
> can reassign them to something else. Functions like scanf, gets,
> puts, printf... read from fd 0 and write to fd 1.
>
> But appart from that, they are like any other fds. So for
> instance a daemon can use them as any other fds (though you'll
> find some tend to open /dev/null on them to avoid side effects
> in case they run other commands).
>
> --
> Stéphane


Thanks
Paresh

  Reply With Quote
Reply

Thread Tools
Display Modes



< Home - Windows Help - MS Office Help - Hardware Support >


New To Site? Need Help?

All times are GMT +5.5. The time now is 08:33 AM.


vBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO
Copyright © 2005-2010, TechTalkz.com. All Rights Reserved - Privacy Policy
Valid XHTML 1.0 Transitional