Solved

Servers started by inetd.

Posted on 1998-11-30
2
298 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 100 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

What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

Question has a verified solution.

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

I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
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.

707 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