Get the file daemon.c
from
http://www.cs.csub.edu/~marc/code/cs376.html.
As with prior labs, make sure you also download all supporting files if you
are putting this code in a new directory. See
Lab 2 for a list of supporting files. Compile the
program with the command:
make daemon
The daemon
program is a very simple TCP/IP server that will host
up to MAX_CHILDREN concurrent clients. It will take whatever is typed in the
client application and either print it to screen or optionally print it to
file if the -log
option is specified. To start daemon
use the command:
daemonOR
daemon -logThis will display the port number to which daemon is bound. Open another terminal and try to telnet to the daemon. For example, if it says it is on port number 19234, the command would be:
telnet localhost 19234To end the connection, within the telnet application give the keyboard sequence CRTL-]. This causes telnet to suspend the connection and give you a telnet shell which looks like
telnet>
. From here, you can give the
command "close" to terminate the current connection, the command "open
<hostname> <portnumber>" to open a new connection (after closing the
current one) and the command "quit" to exit.
To kill the daemon
process, return to the terminal you were
running it in and give the CTRL-C sequence. daemon.c has a signal handler for
CTRL-C which will call parent_terminate()
. This function cleans
up after the process before exiting.
Try running daemon with just one telnet connection at first. Then run daemon with multiple telnet connections at the same time (you will need one terminal for each connection). Pay attention to what is printed to the daemon screen when children connect and disconnect. If running in log mode, you will not see what is typed in the telnet sessions, but you can view the logs once daemon has completed.