UNIX Systems Programming

Preface

UNIX Systems Programming: Communication, Concurrency and Threads is the second edition of Practical UNIX Programming: A Guide to Communication, Concurrency and Multithreading, which was published by Prentice Hall in 1995. We changed the title to better convey what the book is about. Several things have changed, besides the title, since the last edition.

The Internet has become a dominant aspect of computing and of society. Our private information is online; our software is under constant attack. Never has it been so important to write correct code. In the new edition of the book, we tried to produce code that correctly handles errors and special situations. We realized that saying handle all errors but giving code examples with the error handling omitted was not effective. Unfortunately, error handling makes code more complex. We have worked hard to make the code clear.

Another important development since the last edition is the adoption of a Single UNIX Specification, which we refer to as POSIX in the book. We no longer have to decide which vendor's version of a library function to use---there is an official version. We have done our best to comply with the standard.

The exercises and projects make this book unique. In fact, the book began as a project workbook developed as part of a National Science Foundation Grant. It became clear to us, after preliminary development, that the material needed to do the projects was scattered in many places---often found in reference books that provide many details but little conceptual overview. The book has since evolved into a self-contained reference that 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 specified material in a work-along fashion. The topic chapters have many examples 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 in process management, concurrency and communication. These programming exercises satisfy the same need as do laboratory experiments in a traditional science course. You must use the concepts in practice to have real understanding. Exercises are specified for step-by-step development, and many can be implemented in under 100 lines of code.

The table below summarizes the organization of the book---twenty two chapters grouped into four parts. The fifteen topic chapters do not rely on the eight project chapters. You can skip the projects on the first pass through the book.

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 understanding of an advanced topic related to the application. These projects are designed in stages, and most full implementations are a few hundred lines long. Since you don't have to write a large amount of code, you can concentrate on understanding concepts rather than debugging. To simplify the programming, we make libraries available for network communication and logging of output. 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 this book in a course would select several exercises plus 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.

There are many paths through this book. The topic chapters in Part I are prerequisites 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 you are a good C programmer though not necessarily a UNIX C programmer. You should be familiar with C programming and basic data structures. Appendix A covers the bare essentials of program development if you are new to UNIX.

This book includes synopsis boxes for the standard functions. The relevant standards that specify the function appear in the lower-right corner of the synopsis box.

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 authors@usp.cs.utsa.edu. We have done our best to produce an error-free book. However, should you be the first to report an error, we will gratefully acknowledge you on the book web site. Information on the book is available on the WWW site http://usp.cs.utsa.edu/usp. All of the code included in the book can be downloaded from the WWW site.

Acknowledgments
We are very grateful to Mike Speciner and Bob Lynch for reading the entire manuscript and making many useful suggestions. We are especially grateful to Mary Lou Nohr for her careful and intelligent copy-editing. We would also like to express our appreciation to Neal Wagner and Radia Perlman for their encouragement and suggestions.

We have taught undergraduate and graduate operating systems courses from 1988 to date (2003), and much of the material in the book has been developed as part of teaching these courses. The students in these courses have suffered through drafts in various stages of development and have field-tested emerging projects. Their program bugs, comments, complaints, and suggestions made the book a lot better and gave us insight into how these topics interrelate. Some of the students who found errors in an early draft include Joseph Bell, Carlos Cadenas, Igor Grinshpan, Jason Jendrusch and James Manion. 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. NSF (DUE-975093, DUE-9752165 and DUE-0088769) also supported development of tools for exploration and analysis of OS concepts.

We would like to thank Greg Doench, our editor at Prentice Hall, for guiding us through the process and Wil Mara our production editor, for bringing the book to publication. We typeset the book using \LaTeXe, and we would like to express our appreciation to its producers for making this software freely available.

Special thanks go to our families for their unfailing love and support and especially to our children, Nicole and Thomas, who have dealt with this arduous project with enthusiasm and understanding.