In this lab, we will explore two concepts central to many network programs: signal masks and select(). These concepts form the basis of allowing a program to use full-duplex communication.
Read the manual page on signals using the following command:
man 7 signalTo investigate signal processing and signal handlers, change to your directory containing the lab code from Lab 2 (or copy the lab code to a new directory) and type:
make processThis will compile the file
process.c
into a program called
process
. To run the program, use the command:
./process 01000This will output information about the process's current signal mask. The signal mask defines the signals for which the program has signal handlers. Look at the code for
process.c
and see how it is setting up these
signal handlers in main() using sigaddset
.
The files terminal.c
and specio.h
in the lab code
directory use the select() function. Compile the code using the command:
make terminalRun the program using the command:
./terminalThis program steps through three basic terminal modes: raw, cbreak and cooked. Raw mode inputs data character by character with no interpretation (e.g. no signal handling). Cbreak mode responds to SIGINT (CTRL-C) and also uses character by character mode. Cooked mode, also called line mode, gets a full line of input from the user and does interpretation.
Run terminal giving it a variety of input such as printable characters, tabs, control sequences (CTRL-G for bell, CTRL-C for SIGINT, CTRL-Z for SIGSTOP, etc) and escape.
Look at the code for terminal.c
and go to the label
selectloop
in main(). This sets up select() to watch stdin (the
keyboard) for reads (what you've typed) and exceptions. One could expand
select() to watch for other I/O events by using FD_SET on other file
descriptors.
process
according to the
man page?
process.c
as
important signals? Just give the signals, not their purpose
process.c
.
process.c
.
terminal.c
. How is the SIGINT
(CTRL-C) signal handler set up?