?
Solved

Servers started by inetd.

Posted on 1998-11-30
2
Medium Priority
?
304 Views
Last Modified: 2010-04-21
If you have a service defined in /etc/services, and inetd fires up your server when a requested arrives on your port, file descriptors 0, 1 and 2 are available to the server process. As sockets are bidirectional, which ones do we use for send/recv? Should I be using 0 for recv and 1 for send? I have tried using only 0 and it works fine. But why have 0,1 and 2 as socket descriptors as we need only one socket descriptor for operations.

Please e-mail me at vividh@hotmail.com

Thanks in advance.

Vividh
0
Comment
Question by:vividh
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 51

Accepted Solution

by:
ahoffmann earned 200 total points
ID: 2008168
0 is STDIN, 1 is STDOUT and 2 is STDERR
This is a standard, somehow, in UNIX ;-)
0
 
LVL 2

Expert Comment

by:seedy
ID: 2008169
The inet daemon accepts the connection(if it is stream socket), forks and the child process handles the service request.  The child closes all file descriptors other than the accepted socket descriptor, calls dup2 to duplicate the accepted socket descriptor on to file descriptors 0,1 and 2.  The original socket descriptor is also then closed.  Doing this the only file descriptors that are open in the child are 0,1 and 2.  It does few other stuff related to security, and then does an exec to the execute the appropriate server-program to handle the request.

As said above 0,1 and 2 are the same physical socket connection.  I guess the reason may be to provide flexibility in writing your server.  You do not have to use 0 for recv and 1 for send; though it may not hurt either.
0

Featured Post

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tech tip describes how to install the Solaris Operating System from a tape backup that was created using the Solaris flash archive utility. I have used this procedure on the Solaris 8 and 9 OS, and it shoudl also work well on the Solaris 10 rel…
Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.
Suggested Courses
Course of the Month13 days, 15 hours left to enroll

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question