Solved

Servers started by inetd.

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction Regular patching is part of a system administrator's tasks. However, many patches require that the system be in single-user mode before they can be installed. A cluster patch in particular can take quite a while to apply if the machine…
Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
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…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

867 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now