This program illustrates the communication
between clients and servers using FIFOs. The client
requests a file from the server, which runs in the background. Upon receiving
the request from the client through one FIFO, the server writes the file in
blocks through the other FIFO. The server makes the required FIFOs when it is run and the client is required to know the
names of the FIFOs with which it can send requests to
the server. Upon catering to the request the server also dies.
The program can be improved by making
the server a resident process that does not die after catering to a single
client request.
This program illustrates the
communication between clients and servers using PIPEs.
The program forks two processes, the child process requests a file name from
the standard input and sends the requested filename to the parent process
through a PIPE. The server process on receiving a request awakens from it's blocked read state and reads from the requested file
and writes the information in blocks to the child through another PIPE. Again
two pipes are used to simulate two way communication.
The process tries to obtain a lock on
a file. In case of blocked mode of operation, if some other process
hold a lock on the file in question, our process blocks waiting for the
lock to be released. In case of non-blocked operation, the process immediately
returns and does not block.
The process prints on the standard
output the time every n secs, where n is entered by
the user. It uses the alarm() and pause() functions to
generate and catch the SIGALARM signal, which is caught by a signal handler
also written for the program.
The program uses a FIFO to communicate between a
parent and a child. The parent issues the command ls
-l and outputs the result to the child thhrough a FIFO, who then prints the
result on the standard output.
Atomicity in reading and writing is
achieved using file locking. In this program flock()
function has been used.
The program returns the file types of
the files given to it through command line arguments. It uses the lstat() function
to extract information of the files.
The program forks; the parent
generates the SIGUSR1 signal every three seconds using the kill()
function. The child catches the signal and records the information that a signal
is caught. For this the signal handler opens a file (sigfile)
and writes "signal caught" in it.
The program displays a prompt and
receives line input from it. It then forks and the child execlp()s with the command
entered at the prompt. The parent meanwhile waits using waitpid() for the child to
finish before displaying the prompt again.
The server creates a socket in the
Internet domain of SOCK_STREAM type. This ensures TCP as the protocol for
communication in the Internet domain. The port allocated to the server is
displayed on the standard output and can be used by clients to send requests.
It then goes into an infinite loop of waiting and listen()s
for client connection requests. When a request comes it accepts it using accept(). The file descriptor returned by the function is
used to write() requested file in blocks of size 512
bytes.
The client when invoked with
Currently the client receives a
pre-determined file, the program can be improved so
the clients can request arbitrary files.
This program takes the name of the
host to connect to from the command line. It then uses gethostbyname() to resolve
it's address. Then it creates a socket in the Internet domain of the type
SOCK_STREAM and connects to the host's well-known timeofday
server running on port number 13. The server responds to incoming requests by
sending back to the client the time of the day, which the client prints on its
standard output.
The reader and writer processes communicate
with each other through UNIX domain sockets, which use the file system to
facilitate communication.
The type of socket is SOCK_DGRAM.
This program uses datagrams in the Internet domain to interact between the server and the clients. The server sends by not writing but by send()ing data to the client.