alp-ch11-sample-application - 13 0430 CH11 10:46 AM Page...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
A Sample GNU/Linux Application 11 T HIS CHAPTER IS WHERE IT ALL COMES TOGETHER .W E LL DESCRIBE and implement a complete GNU/Linux program that incorporates many of the techniques described in this book.The program provides information about the system it’s running on via a Web interface. The program is a complete demonstration of some of the methods we’ve described for GNU/Linux programming and illustrated in shorter programs.This program is written more like “real-world” code, unlike most of the code listings that we presented in previous chapters. It can serve as a jumping-off point for your own GNU/Linux programs. 11.1 Overview The example program is part of a system for monitoring a running GNU/Linux system. It includes these features: n The program incorporates a minimal Web server. Local or remote clients access system information by requesting Web pages from the server via HTTP. n The program does not serve static HTML pages. Instead, the pages are generated on the fly by modules, each of which provides a page summarizing one aspect of the system’s state.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
220 Chapter 11 A Sample GNU/Linux Application n Modules are not linked statically into the server executable. Instead, they are loaded dynamically from shared libraries. Modules can be added, removed, or replaced while the server is running. n The server services each connection in a child process.This enables the server to remain responsive even when individual requests take a while to complete, and it shields the server from failures in modules. n The server does not require superuser privilege to run (as long as it is not run on a privileged port). However, this limits the system information that it can collect. We provide four sample modules that demonstrate how modules might be written. They further illustrate some of the techniques for gathering system information pre- sented previously in this book.The time module demonstrates using the gettimeofday system call.The issue module demonstrates low-level I/O and the sendfile system call.The diskfree module demonstrates the use of fork , exec , and dup2 by running a command in a child process.The processes module demonstrates the use of the /proc file system and various system calls. 11.1.1 Caveats This program has many of the features you’d expect in an application program, such as command-line parsing and error checking.At the same time, we’ve made some simpli- fications to improve readability and to focus on the GNU/Linux-specific topics dis- cussed in this book. Bear in mind these caveats as you examine the code. n We don’t attempt to provide a full implementation of HTTP. Instead, we implement just enough for the server to interact with Web clients.A real-world program either would provide a more complete HTTP implementation or would interface with one of the various excellent Web server implementations 1 available instead of providing HTTP services directly. n
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 40

alp-ch11-sample-application - 13 0430 CH11 10:46 AM Page...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online