HW3a: HTTP Server, phase A

Part 0: Basic single-process / single-threaded web server



  1. Measurement results

Part 1: Multi-process web server

The basic version of the HTTP server has a limitation: it can handle only one connection at a time. This is serious limitation because a malicious client could take an advantage of this weakness and prevent the server from processing additional requests by sending an incomplete HTTP request. In this part we improve the situation by creating additional processes to handle requests.

The easiest way (from programmer’s point of view) to handle multiple connections simultaneously is to create additional child processes with the fork() system call. Each time a new connection is accepted, instead of processing the request within the same process, we create a new child process by calling fork() and let it handle the request.

The child process inherits the open client socket and processes the request, generating a response. After the response has been sent, the child process terminates.


Requirements (and hints)

  1. Note that the two socket descriptors – the server socket and the new connected client socket – are duplicated when the server forks. Make sure to close anything you don’t need as early as possible. Think about these:

  2. Don’t let your children become zombies… At least not for too long. Make sure the parent process calls waitpid() immediately after one or more child process have terminated.

  3. Modify the logging so that it includes the process id of the child process that handled the request.


  1. The new version of http-server.c

  2. Performance testing result

Part 2: Interprocess communication through shared memory

Reading assignment


Requirements, hints, and recommended order of tasks

  1. Since multiple child processes will need to update the stats, you need to keep them in a shared memory segment. Use anonymous memory mapping described in APUE 15.9.

  2. Perform the hit test from Part 1 and see if your code keeps accurate stats. The request counts may or may not be correct due to race conditions.

  3. Now use POSIX semaphore described in APUE 15.10 to synchronize access to the stats. A few things to think about:

  4. Repeat the performance test and verify that the stats are accurate.

Part 3: Directory listing

The skeleton http-server.c does not handle directory listing. When a requested URL is a directory, it simply responds with 403 Forbidden.


Requirements and hints

Part 4: Directory listing without running /bin/ls


Requirements and hints

Good luck!


This series of assignments were co-designed by Jae Woo Lee and Jan Janak as a prototype for a mini-course on advanced UNIX systems and network programming.

Jan Janak wrote the solution code.

Jae Woo Lee is a lecturer, and Jan Janak is a researcher, both at Columbia University. Jan Janak is a founding developer of the SIP Router Project, the leading open-source VoIP platform.

Last updated: 2014–02–13