Register your product to gain access to bonus material or receive a coupon.
Well written and comprehensive, this book explains complicated topics such as signals and concurrency in a simple, easy-to-understand manner. The book offers an abundance of practical examples and exercises. This book is comparable to other best-selling UNIX books, such as UNIX Network Programming, by Richard Stevens. KEY TOPICS: Covers fundamentals, asynchronous events, concurrency, and communication. MARKET: For programmers in need of a better understanding of UNIX systems programming.
I. FUNDAMENTALS.
1. What Is Concurrency?Multiprogramming and Multitasking. Concurrency at the Applications Level. UNIX Standards. Programming in UNIX. Making Functions Safe. Exercise: Argument Arrays. Additional Reading.
2. Programs and Processes.Layout of a Program Executable. Static Objects. The Process ID. The Process State. Process Creation and the UNIX fork. The wait System Call. The exec System Call. Background Processes and Daemons. The Process Environment. Process Termination in UNIX. Critical Sections. Exercise: Process Chains. Exercise: Process Fans. Exercise: Simple biff. Exercise: News biff. Additional Reading.
3. Files.Directories and Paths. UNIX File Representation. File Handle Representation. Filters and Redirection. Pipes. Reading to and Writing from Files. Nonblocking I/O. The select call. FIFOs. Special Files—The Audio Device. Exercise: Traversing Directories. Exercise: proc Filesystem. Exercise: Audio. Exercise: Terminal Control. Additional Reading.
4. Project: The Token Ring.Forming a Ring. Simple Communication. Mutual Exclusion with Tokens. Mutual Exclusion by Voting. Leader Election on an Anonymous Ring. Token Ring for Communication. A Pipelined Preprocessor. Parallel Ring Algorithms. The Flexible Ring. Additional Reading.
II. ASYNCHRONOUS EVENTS.
5. Signals.Sending Signals. The Signal Mask and Signal Sets. Catching and Ignoring Signals—sigaction. Waiting for Signals—pause and sigsuspend. An Example—biff. System Calls and Signals. siglongjmp and sigsetjmp. Realtime Signals. Asynchronous I/O. Exercise: Dumping Statistics. Exercise: proc Filesystem II. Exercise: Spooling a Slow Device. Additional Reading.
6. Project: Timers.Times in UNIX. Interval Timers. Project Overview. Simple Timers. Setting One of Five Single Timers. Multiple Timers. A Robust Implementation of Multiple Timers. mycron, a Small Cron Facility. POSIX Timer Implementation. Additional Reading.
7. Project: Cracking Shells.A Simple Shell. Redirection. Pipelines. Signals. Process Groups, Sessions, and Controlling Terminals. Handling Background Processes in ush. Job Control. Job Control for ush. Additional Reading.
III. CONCURRENCY.
8. Critical Sections and Semaphores.Atomic Operations. Semaphores. Semaphores in POSIX. Semaphores in System V (Spec 1170). Semaphores and Signals. Exercise: POSIX Unnamed Semaphores. Exercise: POSIX Named Semaphores. Exercise: License Manager. Exercise: System V Shared Memory. Exercise: System V Message Queues. Additional Reading.
9. POSIX Threads.A Motivating Problem: Monitoring File Descriptors. POSIX Threads. Basic Thread Management. User versus Kernel Threads. Thread Attributes. Exercise: Parallel File Copy. Additional Reading.
10. Thread Synchronization.Mutexes. Semaphores. Condition Variables. Signal Handling and Threads. Exercise: Threaded Print Server. Additional Reading.
11. Project: The Not Too Parallel Virtual Machine.The Not Too Parallel Virtual Machine. NTPVM Project Overview. I/O and Testing of Dispatcher. Single Task with No Input. Sequential Tasks. Concurrent Tasks. Broadcast and Barriers. Termination and Signals. Additional Reading.
IV. COMMUNICATION.
12. Client-Server Communication.Client-Server Strategies. The Universal Internet Communication Interface (UICI). Network Communication. Socket Implementation of UICI. Transport Layer Interface (TLI). STREAMS. STREAMS implementation of UICI. Thread-Safe UICI. Exercise: Transmission of Audio. Exercise: Ping Server. Additional Reading.
13. Project: Internet Radio.Overview of the Multiplexer. One-Way Communication. Two-Way Communication. The Transmit Buffer. Multiplexing the Transmit Buffer. Network Receivers. Tuning In and Out. Network Broadcaster. Signal Handling. Additional Reading.
14. Remote Procedure Calls.Basic Operation. Converting a Simple Local Call to an RPC. An Improved Remote Pseudorandom-Number Service. Server State and Idempotent Requests. Remote Idempotent File Service. Binding and Naming of Services. Failures. NFS—Network File System. Threads and Remote Procedure Calls. Exercise: Stateless File Server. Additional Reading.
15. Project: Tuple Space.Linda. Richard, a Simplified Linda. A Simple Richard Tuple Space. Blackboards: A Tuple Space Application. Active Tuples in Richard. Tuple Spaces as Tuples in Richard. A Multithreaded Server for Richard. Additional Reading.
Appendix A. UNIX Fundamentals.Getting Help. Compilation. Makefiles. Header Files. Linking and Libraries. Debugging Aids. User Environment. Additional Reading.
Appendix B. UICI Implementation.UICI Prototypes. Socket Implementation. TLI Implementation. Streams Implementation. Thread-safe UICI Implementation.
Bibliography.PREFACE
Computer systems are evolving rapidly from large single- processor mainframes accessed by terminals toward networks of multiproccessor workstations. Ideas such as concurrency, communication, and multithreading have moved out of the research community and into the commercial world. The applications programmer must understand these concepts, and this book is designed to make the concepts accessible at a detailed level.
The book uses a hands-on approach in a nontraditional sense. In the traditional "hands-on" approach to operating systems, programmers implement a simple operating system or modify an existing operating system to add functionality. The hands-on approach provides an in-depth understanding of basic operating system design, but it is hard for programmers to pursue independently in the field. When this approach is used at the average university, instructors spend considerable class time covering implementation details--- leaving less time to cover a full range of topics. Also, the traditional hands-on approach usually does not provide practical programming experience with advanced synchronization and communication constructs. An alternative to the hands-on approach is a theoretical presentation. Such a "hands-off" course covers more material but does not give the reader an in-depth understanding of the concepts in practice.
Practical UNIX Programming: A Guide to Concurrency, Communication,and Multithreading bridges the gap between the hands-on and hands-off approaches to operating systems by covering programming understandard UNIX. The professional programmer can use the book independently or as a companion to a reference book such as Stevens' Advanced Programming in the UNIX Environment and thereby obtain abetter understanding of operating systems and of systems programming.
A student can use this book as a companion to a traditional textbook, such as Silbershatz and Galvin's Operating Systems Concepts or Tanenbaum's Modern Operating Systems, to learn about operating systems by doing. The exercises and projects make this book unique. In fact, the book began as a project workbook. It became clear after preliminary development that the material needed to do the projects was scattered in many places---often found in reference books that provide manydetails but little conceptual overview. The book has since evolved into a self-contained reference which relies on the latest UNIX standards.
The book is organized into four parts, each of which contains topic chapters and project chapters. A topic chapter covers the specifiedmaterial in a work-along fashion. The topic chapters have manyexamples and short exercises of the form "try this" or "what happens if." The topic chapters close with one or more exercise sections. The book provides programming exercises for many fundamental concepts inprocess management, concurrency, and communication. These programming exercises satisfy the same need as do laboratory experiments in atraditional science course. It is necessary to use the concepts in order to understand them fully.
Exercises are specified for step-by-step development and most can be implemented in under 100 lines of code. Project chapters integrate material from several topic chapters by developing a more extensive application. The projects work on two levels. In addition to illustrating the programming ideas, the projects lead to an understanding of an advanced topic related to the application. These projects are designed in stages and most fullimplementations are a few hundred lines long. Since a large amount of code does not need to be written, the programmer can concentrate on understanding concepts rather than debugging code. In order to simplify the programming, we make libraries available for network communication. The table below summarizes the organization of the book---fifteen chapters grouped into four parts. The nine topic chapters do not rely on the six project chapters, and a reader can skip the projects on the first pass through the book.
Part
Topic Chapter Project Chapter
I Concurrency Fundamentals Processes Files The Token Ring
II Signals Asynchronous Timers Events Cracking Shells Semaphores
III POSIX Threads Concurrency Thread Synch Virtual Machine Client-Server
IV Internet Radio Communication RPCs Tuple Space
There are many paths through this book. The three topic chapters inPart I are prerequisite for the rest of the book. Readers can cover Parts II through IV in any order after the topic chapters of Part I.
The exception is the discussion at the end of later chapters about interactions (e.g., how threads interact with signals). We have assumed that the readers of this book are good C programmers though not necessarily UNIX C programmers. The reader should be familiar with C programming and basic data structures. Appendix A covers the bare essentials of program development for readers who are new to UNIX. UNIX programmers probably know much of the material found in Chapters 2 and 3, but the coverage here is detailed and later projects rely heavily on it.
A reader should not assume that reading a chapter bestows understanding unless he or she has successfully developed some programs that use the concepts. For a professional programmer, the exercises at the end of the topic chapters provide a minimal hands-on introduction to the material. Typically, an instructor using thistext for an operating systems course would select several exercisesplus one of the major projects for implementation during a semester course. Each project has a number of variations, so the projects can be used in multiple semesters.
This book includes a synopsis for many of the standard functions. The relevant standards that specify the function appear in the lower right corner of the synopsis box. In general, ISO C is a subset of POSIX.1 and Spec 1170. In some cases the list of required header files differs between standards, with some of the header files being optional for some standards. In these cases the synopsis box lists all relevant header files. A book like this is never done, but we had to stop somewhere. We welcome your comments and suggestions.
You can send email to us at pup@vip.cs.utsa.edu.
Information on the book is available on WWW sitehttp://vip.cs.utsa.edu/pup. All of the code included in the book can be obtained from the WWW site or by anonymous ftp to vip.cs .utsa.eduin the directory pub/pup.
Acknowledgments
Our foremost acknowledgment goes to Neal Wagner---friend, colleague, and policeman of the passive voice. Neal was responsible more than anyone else for our writing this book. After all, he argued, since we already had the projects, how much more work could writing the book be? He followed up with lots of support---endless reading and critiquing drafts that greatly improved the book. Our second acknowledgment goes to the dozen or so undergraduate and graduate operating systems classes we taught in the years from 1988 and 1995 when we were developing this material. We are grateful to the students in these courses for suffering through drafts in various stages of development and for field-testing emerging projects. Their program bugs, comments, complaints, and suggestions made the book alot better and gave us insight into how these topics interrelate. We would also like to acknowledge many other people who read the book and made suggestions for improvement or correction or helped in other ways. Dennis Cadena read an entire draft and made many suggestions. Other people who have commented or helped include Jeff Adamek, Laura Connor, Sandy Dykes, Richard Hatch, Philip Helsel, Bob Hiromoto, Clint Jeffery, George Leach, C. Ed Nicol, Richard Rybacki, Devang Shah, Dennis Wenzel, and Andrea Whitlock.
We are grateful to Greg Doench, our editor at Prentice Hall, and Meg Cowen, his assistant, for guiding us through the process. They helped us improve the book by gentle suggestions and support without pressure. We would also like to thank Jane Bonnell, our production editor, for all of her help in bringing the book to publication. It was a pleasure to work with these professionals. A number of anonymous reviewers made excellent suggestions which greatly helped in our revision for final publication. We typeset the book using LaTeX 2e, and we would like to express our appreciation to its producers for making this software freely available. Special thanks go to our spouses and children for enduring with us the arduous trek that preparing this book turned out to be. Finally, we would like to acknowledge the National Science Foundation for providing support through the NSF-ILI grant USE-0950497 to build a laboratory so that we had the opportunity to develop the original curriculum upon which this book is based.