Home > Store

Practical UNIX Programming: A Guide to Concurrency, Communication, and Multithreading

Register your product to gain access to bonus material or receive a coupon.

Practical UNIX Programming: A Guide to Concurrency, Communication, and Multithreading

Book

  • Sorry, this book is no longer in print.
Not for Sale

About

Features

  • Two types of programming problems— Laboratory exercises that can be implemented in less than 100 lines of code, and more extensive laboratory projects that apply the concepts in semi-practical settings.
  • Simplified libraries for network communication in order to simplify the programming.
  • Many examples and short exercises in the form “try this” and “what happens if” in each chapter.

Description

  • Copyright 1996
  • Edition: 1st
  • Book
  • ISBN-10: 0-13-443706-3
  • ISBN-13: 978-0-13-443706-4

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.

Sample Content

Table of Contents

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.
Index.

Preface

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.

Updates

Submit Errata

More Information

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020