Solved

Servers started by inetd.

Posted on 1998-11-30
2
267 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
Comment Utility
0 is STDIN, 1 is STDOUT and 2 is STDERR
This is a standard, somehow, in UNIX ;-)
0
 
LVL 2

Expert Comment

by:seedy
Comment Utility
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
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 how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
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.

772 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

15 Experts available now in Live!

Get 1:1 Help Now