Sample Chapter
Total Page:16
File Type:pdf, Size:1020Kb
CONTENTS PREFACE xi PART 1 BEHIND THE DESKTOP 1 1 BEHIND THE DESKTOP 3 1.1 What is an operating system? 3 1.2 Emulation 5 1.3 What an operating system does 10 1.4 Event-driven systems 15 1.5 Protection mechanisms 17 1.6 Virtual resources 18 1.7 The evolution of operating system designs 20 1.8 What makes a good operating system? 23 1.9 Examples of operating systems 24 1.10 Summary 27 1.11 Additional resources 27 1.12 Glossary 28 1.13 References 29 2 USING AN OPERATING SYSTEM 31 2.1 The programmer’s view 31 2.2 Event-driven programming 34 2.3 Exceptions 41 2.4 The shell 43 2.5 Graphical shells 55 2.6 Summary 56 2.7 Additional resources 57 2.8 Glossary 57 2.9 References 59 v vi J CONTENTS 3 FILESYSTEMS 60 3.1 Files and directories 60 3.2 Pathnames and filenames 62 3.3 Multiple filesystems 65 3.4 File types 69 3.5 Filenames 72 3.6 File versions 73 3.7 Links and shortcuts 74 3.8 File locking 76 3.9 File attributes 77 3.10 Disk structure 78 3.11 Backup systems 81 3.12 Example filesystems 82 3.13 Summary 95 3.14 Additional resources 96 3.15 Glossary 96 3.16 References 98 4 PROCESSES AND THREADS 99 4.1 The view from inside a process 99 4.2 Threads 100 4.3 Interprocess communication 103 4.4 Synchronisation 106 4.5 Mutual exclusion 108 4.6 Synchronization in high-level languages 112 4.7 Deadlock 118 4.8 Livelock 125 4.9 Starvation and priority inversion 127 4.10 The Dining Philosophers Problem 128 4.11 Summary 131 4.12 Additional resources 132 4.13 Glossary 132 4.14 References 134 PART 2 BENEATH THE DESKTOP 135 5 MEMORY MANAGEMENT 137 5.1 Address spaces 137 5.2 Virtual memory 142 5.3 Demand paging 146 5.4 Swapping 147 5.5 Thepagetable 148 5.6 Shared memory 151 5.7 Page faults 155 5.8 Copy-on-write 160 5.9 Segmentation 160 5.10 Summary 162 5.11 Additional resources 163 5.12 Glossary 163 5.13 References 164 CONTENTS J vii 6 HARDWARE SUPPORT 165 6.1 How computers work 165 6.2 User and kernel modes 171 6.3 Kernel memory 177 6.4 System calls 179 6.5 Memory management hardware 180 6.6 Caching 182 6.7 Power management 186 6.8 Hardware failure 189 6.9 Summary 192 6.10 Additional resources 192 6.11 Glossary 193 6.12 References 195 7 THE KERNEL 197 7.1 Kernel responsibilities 197 7.2 Implementing threads 199 7.3 Kernel objects 202 7.4 Process management 210 7.5 Scheduling 214 7.6 Exception handling 217 7.7 Memory management 219 7.8 Kernel processes 221 7.9 Daemons 222 7.10 Summary 225 7.11 Additional resources 226 7.12 Glossary 226 7.13 References 227 8 DEVICE DRIVERS 229 8.1 The I/O subsystem 229 8.2 What are device drivers? 231 8.3 Types of device 234 8.4 Buffering 236 8.5 Device driver structure 237 8.6 Linux device drivers 239 8.7 Windows device drivers 246 8.8 Some specific examples 247 8.9 Summary 255 8.10 Additional resources 256 8.11 Glossary 257 8.12 References 259 PART 3 BEYOND THE DESKTOP 261 9 MULTIPROCESSOR SYSTEMS 263 9.1 Multiprocessor systems 263 9.2 Multicomputer systems 271 9.3 Clients and servers 273 9.4 Distributed filesystems 276 viii J CONTENTS 9.5 Distributed processing 283 9.6 Distributed object frameworks 292 9.7 Summary 297 9.8 Additional resources 298 9.9 Glossary 299 9.10 References 302 10 NETWORKING TECHNOLOGIES 304 10.1 Networking 304 10.2 Sockets 307 10.3 TCP/IP 314 10.4 Multicasting 323 10.5 Machine identification 326 10.6 Summary 328 10.7 Additional resources 328 10.8 Glossary 328 10.9 References 331 11 DISTRIBUTED SYSTEMS 332 11.1 Distributed system issues 332 11.2 Distributed global time 334 11.3 Distributed mutual exclusion 339 11.4 Distributed deadlock 342 11.5 Fault tolerance 344 11.6 Cluster systems 348 11.7 Distributed shared memory 356 11.8 Distributed operating systems 357 11.9 Summary 361 11.10 Additional resources 362 11.11 Glossary 363 11.12 References 364 12 SAFETY AND SECURITY 366 12.1 Security issues 366 12.2 Password protection 367 12.3 Encryption techniques 371 12.4 System attacks 378 12.5 Sandboxes 387 12.6 Firewalls and proxies 391 12.7 Summary 392 12.8 Additional resources 393 12.9 Glossary 394 12.10 References 396 GLOSSARY 397 BIBLIOGRAPHY 419 INDEX 425 CHAPTER 1 « BEHIND THE DESKTOP Let’s begin by looking at what an operating system does. For most people, what they see is a graphical desktop which lets them run programs, organise information in files, categorise files into directories or folders, copy files from one place to another, and so on. Many people are misled into thinking that the graphical desktop is the operating system itself, whereas in fact it’s just the tip of a largely invisible iceberg. 1.1 J WHAT IS AN OPERATING SYSTEM? I’m sitting here writing this book on a computer which is running a popular oper- ating system from Microsoft called Windows 2000, which like most modern systems has a graphical user interface (GUI) which I use to control it. The desktop it provides on the screen is fairly distinctive in appearance, so much so that many people identify the operating system with the desktop. There are a number of icons representing programs and documents on the left of the screen, and several windows corresponding to programs that I’m running. At the bottom of the screen there is a taskbar containing buttons which can be used to control the programs that are running. This is shown in Figure 1.1. Of the windows displayed on the screen, the foremost one is used by the word processing package I’m using to write this chapter. It appears in front of the other windows on the screen, some of which are partly covered up by it. In one of these windows, an MP3 player is entertaining me with music as I write; I can see some of it, but not all, as the MP3 player’s window is partially covered by my word proces- sor’s window. Several other programs are also active at the same time. Each of these programs is completely independent of all the others, and each one behaves as if it 3 4 J INTRODUCTION TO OPERATING SYSTEMS Figure 1.1 A Windows 2000 desktop. is being executed by an independent computer. These independent ‘computers’ (or more accurately, computations) are referred to as processes. A process behaves like a complete self-contained computer, and it is possible to have multiple processes which are executing separate copies of the same program, just as you can have several computers executing separate copies of the same program. And like separate computers, each process executes independently of all the others that are running at the same time. Question 1.1 What is the relationship between a process, a program and a processor? The operating system is the program which is responsible for coordinating the activities of the various processes that my PC is executing. As I move the mouse or presskeysonthekeyboard,orasdataarrivesovermynetworkconnection,the BEHIND THE DESKTOP J 5 operating system identifies the process to be notified of these events. The indi- vidual processes then respond to these events in their own individual ways, according to the dictates of the programs they are executing. I use the mouse and keyboard to interact with the process associated with the foremost window (the active window), or to bring another window to the front so that I can interact with it. The active window handles all the mouse events that occur while the mouse is within its boundaries, and all keyboard events except a few special key combina- tions are also handled by the active window. From the point of view of each process itappearsthattheprocesshasitsownkeyboardandmouse,justasaseparate computer would. And like a separate computer, each process has its own separate display which appears as a separate window on the desktop. So what is the operating system? Is it the desktop? No, the desktop is just a display area being managed by another perfectly ordinary program. It uses a window which occupies the entire screen, and which acts as a background for windows belonging to other programs. It is started when the operating system first starts up, and its main responsibility is to ask the operating system to create a new processwheneveraniconrepresentingaprogramisactivated.Itthusactsasthe ‘parent’ for all the other processes that I start. The operating system itself is practically invisible. It is responsible for coordi- nating the activities of the whole system without making itself intrusively visible, and for sharing the resources of the computer (processor time, memory, and so on) according to the needs of the processes running on the machine. It provides a virtual environment for each individual process, so that each virtual environ- ment is practically indistinguishable from a real computer. It also provides facili- ties such as the ability to create new processes. 1.2 J EMULATION Once upon a time I used to own an Apple II, a well-known machine of the 1980s which supported a large number of popular games, but it broke down several years ago.