Summary and explanation of UNIX systems programming assignments:

Programs on files, signals, IPC are documented below:

 

1.      CLIENT SERVER COMMUNICATION USING FIFOs (fifoserver.c,fifoclient.c)

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.

 

 

2.      CLIENT SERVER COMMUNICATION USING PIPEs (pipe.c)

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.

 

 

3.      BLOCKED AND NON-BLOCKED MODE OF OPERATION (blocked.c)

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.

 

 

4.      CLOCK SIMULATION (clock.c)

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.

 

 

5.      FILE LISTING (listfiles.c)

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.

 

 

6.      ATOMIC READ-WRITE ON FILES (assignment1.c)

Atomicity in reading and writing is achieved using file locking. In this program flock() function has been used.

 

 

7.      FILE TYPE FINDING (prog3.c)

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.

 

 

8.      SIGUSR1 CATCHING PROGRAM (sig.c)

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.

 

 

9.      COMMAND LINE EMULATOR (prompt.c)

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.

 

 

 

Programs on SOCKETS, and  their documentation is given below:

 

1.       FILE SERVER AND CLIENT (fileserver.c,fileclient.c)

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 and arguments uses the gethostbyname() function to get address of the . It then makes a socket in the Internet domain of type SOCK_STREAM. Then it sends a connection request to the host using connect(). Once the connection is established the server sends and the client receives.

Currently the client receives a pre-determined file, the program can be improved so the clients can request arbitrary files.

 

2.      DATECLIENT (dateclient.c)

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.

 

3.      DATAGRAM UNIX DOMAIN CLIENT SERVER INTERACTION (datagramsockreader.c,datagramsockwruter.c)

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.

 

4.      DATAGRAM INTERNET DOMAIN CLIENT SERVER INTERACTION (datagraminternetsocketreader.c,datagraminternetsocketwriter.c)

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.

 

 

 

 

Previous     Next     Outline

 

Download the programs

Hosted by www.Geocities.ws

1 1