ebook img

Unix® for Programmers and Users PDF

720 Pages·2003·3.277 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Unix® for Programmers and Users

Unix® for Programmers and Users Third Edition Graham Glass and King Ables Pearson Education,Inc. Upper Saddle River,New Jersey 07458 Library of Congress Cataloging-in-Publication Data CIP data on file Vice President and Editorial Director,ECS:Marcia Horton Executive Editor:Petra Recter Editorial Assistant:Renee Makras Vice President and Director of Production and Manufacturing,ESM:David W.Riccardi Executive Managing Editor:Vince O’Brien Assistant Managing Editor:Camille Trentacoste Production Editor:Lakshmi Balasubramanian Director of Creative Services:Paul Belfanti Creative Director:Carole Anson Art Director:Jayne Conte Cover Designer:Bruce Kenselaar Art Editor:Gregory Dulles Manufacturing Manager:Trudy Pisciotti Manufacturing Buyer:Lisa McDowell Marketing Manager:Pamela Shaffer Marketing Assistant:Barrie Reinhold ©2003 Pearson Education,Inc. Pearson Prentice Hall Upper Saddle River,NJ 07458 All rights reserved.No part of this book may be reproduced,in any form or by any other means,without permission in writing from the publisher. The author and publisher of this book have used their best efforts in preparing this book.These efforts include the development,research,and testing of the theories and programs to determine their effective- ness.The author and publisher make no warranty of any kind,expressed or implied,with regard to these programs or the documentation contained in this book.The author and publisher shall not be liable in any event for incidental or consequential damages in connection with,or arising out of,the furnishing, performance,or use of these programs. Printed in the United States of America 10 9 8 7 6 5 4 3 2 1 ISBN 0-13-046553-4 Pearson Education Ltd.,London Pearson Education Australia Pty.Ltd.,Sydney Pearson Education Singapore,Pte.Ltd. Pearson Education North Asia Ltd.,Hong Kong Pearson Education Canada,Inc.,Toronto Pearson Educación de Mexico,S.A.de C.V. Pearson Education—Japan,Tokyo Pearson Education Malaysia,Pte.Ltd. Pearson Education,Inc.,Upper Saddle River,New Jersey to Truth and Beauty, wherever they are found and to Freedom,and all who have sacrificed for it Trademark Information AIX is a trademark of International Business Machines Corporation. Ethernet is a registered trademark of Xerox Corporation. FreeBSD is a trademark of Berkeley Software Design,Inc. GNU is a trademark of the Free Software Foundation. HP-UX is a registered trademark of the Hewlett-Packard Company. Itanium is a registered trademark of Intel Corporation. IRIX is a registered trademark of Silicon Graphics,Inc. Java is a trademark of Sun Microsystems,Inc. KDE and K Desktop Environment are trademarks of KDE e.V. Linux is a trademark of Linus Torvalds. MacOS is a registered trademark of Apple Computer. Microsoft Windows,Windows NT,and Windows 2000 are registered trademarks of Microsoft Corporation. Netscape is a registered trademark of Netscape Communications Corporation. SCO and Unixware are trademarks of Caldera. Solaris,Sparc,and Open Windows are trademarks of Sun Microsystems,Inc. Tru64 is a trademark of the Hewlett-Packard Company. UNIX is a registered trademark of The Open Group. VMS and Open VMS are registered trademarks of the Hewlett-Packard Company. X Window System is a trademark of The Open Group. iv Preface ABOUT THE AUTHORS Graham Glass graduated from the University of Southampton,England,with a bachelor’s degree in computer science and mathematics in 1983.He emigrated to the United States and obtained his master’s degree in computer science from the University of Texas at Dallas in 1985.He then worked as a UNIX/C systems analyst and became heavily in- volved with research in neural networks and parallel distributed processing.He later taught at the University of Texas at Dallas,covering a wide variety of courses,including UNIX, C, assembly language, programming languages, C++, and Smalltalk. He co- founded a corporation called ObjectSpace and currently trains and consults for such companies as DSC Corporation,Texas Instruments, Northern Telecom, J.C. Penney, and Bell Northern Research,using his OOP and parallel systems knowledge to design and build a parallel object-oriented computer system and language based on the Inmos T9000 transputer chip.In his spare time,he writes music,scuba dives,skis,and occasionally sleeps. King Ables earned his bachelor’s degree in computer science from the Universi- ty of Texas at Austin in 1982.He has been a UNIX user,developer,systems administra- tor, or consultant since 1979, working at both small start-up companies and large corporations. He has provided support and training, developed UNIX product soft- ware and systems tools,and written product documentation and training materials.In the 1990s,he was the sole proprietor of a UNIX consulting concern in Austin before deciding to move to the mountains of Colorado.Prior to this project,he published a book on UNIX systems administration.He has written many magazine articles on var- ious UNIX topics and holds a software patent on an e-commerce privacy mechanism. His professional interests include networking security and Internet privacy, but he likes hiking and skiing a bit more. ABOUT THE BOOK One of my jobs before writing this book was to teach UNIX to a variety of individuals, including university students, industry C hackers, and, occasionally, friends and col- leagues.During that time,I acquired a large amount of knowledge,both in my head as well as in the form of a substantial library,that I often thought would be good to put into book form.When I began preparing my university lecture series about UNIX,I v vi Preface found that none of the available UNIX textbooks suited my purpose—they were either too unstructured,too specialized,or lacking in suitable exercises and projects for my students.In response to this situation,I wrote the very first version of the current book. After a couple of years of using it,I completely rewrote it,giving careful thought to the organization of the new material.I decided to group the information on the basis of various typical kinds of UNIX users,allowing the book to be utilized by a good range of people without completely going over the top (or underneath) anyone’s head.One tricky decision concerned the level of detail to include about things like utilities and system calls.Most of these have a large number of specialized options and features that are rarely used,and to document them all and still cover the range of topics that I had targeted would result in a book about two feet thick.Because of this,I’ve included in- formation only about the most common and useful features of utilities,shells,and sys- tem calls.I include references to other commercially available books for more detail. This hybrid-book approach seemed like a good compromise;I hope that you agree. This edition adds a chapter on the Bourne Again Shell (also called “bash”),which has become more important because of its integral position in Linux.We have also up- dated the UNIX/Linux version information and X desktop and window manager de- tails, expanded the existing coverage of vi, perl, and IPv6, and added and improved some command descriptions, quizzes, and exercises. Many organizational improve- ments,including new figure numbering,should make the book easier to use,as well. LAYOUT OF THE BOOK UNIX is a big thing.To describe it fully requires an explanation of many different top- ics from several different angles,which is exactly what I’ve tried to do.The book is split into the following sections,each designed for a particular kind of user: 1. What is UNIX? 2. UNIX Utilities for Nonprogrammers 3. UNIX Utilities for Power Users 4. The UNIX Shells 5. The Bourne Shell 6. The Korn Shell 7. The C Shell 8. The Bourne Again Shell 9. Networking 10. The Internet 11. Windowing Systems 12. C Programming Tools 13. Systems Programming 14. UNIX Internals 15. System Administration 16. The Future Appendix Bibliography Preface vii I recommend that the various categories of user read the chapters as follows: Category of user Chapters Day-to-day casual users 1,2 Advanced users 1,2,3,4,9,10,11 Programmers 1 thru 13,16 System analysts 1 thru 14,16 Wizards Everything (of course!) LAYOUT OF THE CHAPTERS Every chapter in this book has the following standard prologue: Motivation Why it’s useful to learn the material that follows. Prerequisites What the reader should know in order to negotiate the chapter successfully. Objectives A list of the topics presented. Presentation A description of the method by which the topics are presented. Utilities A list of the utilities covered in the chapter (when appropriate). System calls A list of the system calls covered in the chapter (when appropriate). Shell commands A list of the shell commands covered in the chapter (when appropriate). viii Preface In addition,every chapter ends with a review section,which contains the follow- ing items: Checklist A recap of the topics. Quiz A quick self-test. Exercises A list of exercises,rated easy,medium,or hard. Projects One or more related projects,rated easy,medium,or hard. A GUIDE FOR TEACHERS As I mentioned earlier,this book was originally written for an audience of undergrad- uate and graduate students.I suggest that a lecture series based on the book could be designed as follows: • If the students don’t know the C language,then a medium-paced course could begin with Chapters 1,2,4,and 12.The lecturer could then introduce the students to C and use the contents of Chapter 13for class exercises and projects. • If the students already know the C language,then a medium-paced course could include Chapters 1,2,4,7,12,13,and 14.Projects focusing on parallel processing and interprocess communication will ensure that the students end up with a good knowledge of UNIX fundamentals. • If the students know the C language and are enthusiastic,I suggest that all of the chapters with the exception of Chapters 3,5,and 6be covered in one semester.I know this is possible,as I’ve taught the class that way! NOMENCLATURE Throughout this book, there are references to UNIX utilities, shell commands (i.e., commands that are part of a command shell itself), and system calls (UNIX library functions).It’s quite easy to confuse these three things,so I adopted a consistent way to differentiate them: • UNIX utilities are always written in boldface,like this:“The mkdirutility makes a directory.” • Shell commands are always written in italics,like this:“The historycommand lists your previous commands.” Preface ix • System calls are always followed by parentheses,like this:“The fork () system call duplicates a process.” Formal descriptions of utilities,shell commands,and system calls are supplied in a box, using a modified-for-UNIX Backus–Naur notation.The conventions of this notation are fairly simple and are described fully in the appendix.As an example,here’s a de- scription of the UNIX manutility: Utility:man[chapter]word man-kkeyword The first usage of mandisplays the manual entry associated with word.A value for chapter is optional.If no chapter number is specified,the first entry found is displayed.The second usage of mandisplays a list of all the manual entries that containkeyword. All utilities,shell commands,and system calls,including the page numbers of the scripts and programs that use them,are fully cross-referenced in the appendix. Sample UNIX sessions are presented in a Courier font.Keyboard input from the user is always displayed in italics,and annotations are always preceded by ellipses (...). Here’s an example: $ ls ... generate a directory listing. myfile.txt yourfile.txt $ whoami glass $ _ ... a new prompt is displayed. REFERENCES TO OTHER BOOKS For the same reason that it’s good to reuse existing code,it’s also good to use other people’s reference material when it doesn’t interfere with the natural flow of the pre- sentation. Information that we consider to be too specialized for this book is noted with a reference to a publication listed in the bibliography at the end of the book.For example, “For information concerning a port of UNIX to a 68030 processor,see p.426 of Wait 1987.” The information is usually the name of the primary author and the year of publi- cation;in the preceding quote,the book is entitled “UNIX papers.”Where we refer- ence specific pages,it is,of course,possible that future editions of these books will have different page numbers.In these cases,the reference will hopefully still remain reason- ably close to the quoted page number.

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.