OS Notes
OS Notes
Operating System Functions: The operating system's tasks, in the most general sense, fall into six categories: 1. Process management 2. Memory management 3. File Management 4. Device management 5. Security 6. Command Interpretation While there are some who argue that an operating system should do more than these six tasks, and some operating system vendors that build many more utility programs and auxiliary functions into their operating systems, these six tasks define the core of essentially all operating systems. 1. Process Management The heart of managing the processor comes down to two related issues: First, ensuring that each process and application receives enough of the processor's time to function properly and, second, using as many processor cycles for real work as is possible. A process is a program in execution. The main objective of this module of an OS is to manage the processes submitted in a manner so as to minimize the idle time of the various processors. It takes care of creation and deletion of processes, scheduling of various system resources to the different processes requesting them, and providing mechanisms for synchronization and communication among processes. Memory management: takes care of the allocation and deallocation of memory space to the various programs in need of the resource. Main responsibilities are * Keeping track of which parts of memory are currently being used and by whom * decide which processes are to be loaded into memory when memory space becomes available * allocate and deallocate memory space as needed It's tempting to think of a process as an application, but that gives an incomplete picture of how processes relate to the operating system and hardware. The application you see (word processor or spreadsheet or game) is, indeed, a process, but that application may cause several other processes to begin, for tasks like communications with other devices or other computers. There are also numerous processes that run without giving you direct evidence that they ever exist. A process, then, is software that performs some action and can be controlled -- by a user, by other applications or by the operating system. It is processes, rather than applications, that the operating system controls and schedules for execution by the CPU. In a single-tasking system, the schedule is straightforward. The operating system allows the application to begin running, suspending the execution only long enough to deal with interrupts and user input. Interrupts are special signals sent by hardware or software to the CPU. It's as if some part of the computer suddenly raised its hand to ask for the CPU's attention in a lively meeting. While interrupts add some complication to the execution of processes in a single-tasking system, the job of the operating system becomes much more complicated in a multi-tasking system. Now, the operating system must arrange the execution of applications so that you believe that there are several things happening at once. This is complicated because the CPU can only do one thing at a time. In order to give the appearance of lots of things happening at the same time, the operating system has to switch between different processes thousands of times a second. This process swapping happens without direct user interference, and each process will get enough CPU time to accomplish its task in a reasonable amount of time. Trouble can come, though, if the user tries to have too many processes functioning at the same time. In a system with two or more CPUs, the operating system must divide the workload among the CPUs, trying to balance the demands of the required processes with the available cycles on the different CPUs. Some operating systems (called asymmetric) use one CPU for their own needs, dividing application processes among the remaining CPUs. Other operating systems (called symmetric) divide themselves among the various CPUs, balancing demand versus CPU availability even when the operating system itself is all that's running. Even if the operating system is the only software with
Manjari Lal
Operating Systems
execution needs, the CPU is not the only resource to be scheduled. Memory management is the next crucial step in making sure that all processes run smoothly. 2. Memory and Storage Management When an operating system manages the computer's memory, there are two broad tasks to be accomplished. First, each process must have enough memory in which to execute, and it can neither run into the memory space of another process, nor be run into by another process. Next, the different types of memory in the system must be used properly, so that each process can run most effectively. The first task requires the operating system to set up memory boundaries for types of software, and for individual applications. When applications begin to be loaded into memory, they are loaded in block sizes determined by the operating system. If the block size is 2 kilobytes, then every process that is loaded will be given a chunk of memory that is a multiple of 2 kilobytes in size. Applications will be loaded in these fixed block sizes, with the blocks starting and ending on boundaries established by words of 4 or 8 bytes. These blocks and boundaries help to ensure that applications won't be loaded on top of one another's space by a poorly calculated bit or two. With that ensured the larger question of what to do when the 500 kilobyte application space is filled. In most computers it's possible to add memory beyond the original capacity. For example, you might expand RAM from 1 to 2 megabytes. This works fine, but tends to be relatively expensive. It also ignores a fundamental fact -- most of the information that an application stores in memory is not being used at any given moment. A processor can only access memory one location at a time, so the vast majority of RAM is unused at any moment. Since disk space is cheap compared to RAM, then moving information in RAM to hard disk intelligently can greatly expand RAM space at no cost. This technique is called Virtual Memory Management. The operating system must balance the needs of the various processes with the availability of the different types of memory, moving data in blocks called pages between available memories as the schedule of processes dictates. 3. File Management A file is a collection of related information. Every file has a name, its data and attributes. Name of a file uniquely identifies it in a system. Attributes of a file contain other information about the file, such as date and time of its creation, date and time of last access, date and time of last update, its current size, its protection features, etc. List of attributes maintained for a file varies from one system to another. File management module of an operating system takes care of file related activities, such as structuring, accessing, naming, sharing, and protection of files. The rules for naming files vary from one operating system to another. E.g. MS-DOS allows only up to 8 characters for a file name, while Windows allows 255 characters. Some operating systems (such as UNIX) distinguish between upper-case and lower-case letters, whereas others (such as MS-DOS) do not. Some operating systems allow letters and numbers to be used in file names, whereas others allow special characters. Many operating systems support file names having two or more parts, with different parts separated by a period (dot). MS-DOS supports two part file name in which first part can have 1 to 8 characters, and the optional second part can have 1 to 3 characters. In UNIX, a file name may have more than two parts. Files systems are very large. Files have to be organized. Usually a two-level organization is done: 1. The file system is divided into partitions. By default there is at least one partition. Partitions are nothing but virtual disks with each partition considered as a separate storage device. 2. Each partition has information about the files in it. This information is nothing but a table of contents. It is known as a directory / folder. The directory maintains information about the name, location, size and type of all files in the partition. A directory has a logical structure. This is dependent on many factors including operations that are to be performed on the directory like search for file/s, create a file, delete a file, list a directory, rename a file and traverse a file system.
Manjari Lal
Operating Systems
4. Device Management The path between the operating system and virtually all hardware not on the computer's motherboard goes through a special program called a driver. Drivers take data that the operating system has defined as a file and translate them into streams of bits placed in specific locations on storage devices, or a series of laser pulses in a printer. One reason that drivers are separate from the operating system is so that new functions can be added to the driver-and thus to the hardware subsystems - without requiring the operating system itself to be modified, recompiled and redistributed. Managing input and output is largely a matter of managing queues and buffers, special storage facilities that take a stream of bits from a device, and release them to the CPU. This function is especially important when a number of processes are running and taking up processor time. The operating system will instruct a buffer to continue taking input from the device, but to stop sending data to the CPU while the process using the input is suspended. Then, when the process needing input is made active once again, the operating system will command the buffer to send data. 5. Security Computer security deals with protecting various resources and information of a computer system against destruction and unauthorized access. It involves: external and internal security. External security deals with securing a computer system against external factors such as fires, floods, earthquakes, leaking out of stored information by a person who has access to information, etc. Commonly used methods for external security include maintaining backup copies of stored information at places far away from the original information, allowing access to sensitive information to trusted employees, etc. Internal security deals with the following aspects: 1. User authentication: Identification and Authentication is a technical measure that prevents unauthorized people (or unauthorized processes) from entering an IT system. Authentication is the means of establishing the validity of a user's claimed identity to the system. There are three means of authenticating a user's identity which can be used alone or in combination: something the individual knows (a secret -- e.g., a password, Personal Identification Number (PIN), or cryptographic key); something the individual possesses (a token -- e.g., an ATM card or a smart card); and something the individual is (a biometrics -- e.g., characteristics such as a voice pattern, handwriting dynamics, or a fingerprint). 2. Access control: Access control usually requires that the system be able to identify and differentiate among users. Even when a user passes user authentication phase and is allowed to use a computer, some mechanism is needed to restrict the users access to those resources / information that he / she is authorized to access. Operating Systems normally maintain Access Control Lists that specify which users can have what types of accesses on various system resources. 3. Cryptography: Cryptography is used to protect data both inside and outside the boundaries of a computer system. Outside the computer system, cryptography is sometimes the only way to protect data. While in a computer system, data is normally protected with logical and physical access controls (perhaps supplemented by cryptography). However, when in transit across communications lines or resident on someone else's computer, data cannot be protected by the originator's logical or physical access controls. Cryptography provides a solution by protecting data even when the data is no longer in the control of the originator. Cryptography can increase security in user authentication techniques. Instead of communicating passwords over an open network, authentication can be performed by demonstrating knowledge of a cryptographic key. Using these methods, a one-time password, which is not susceptible to eavesdropping, can be used. User authentication can use either secret or public key cryptography. Interdependencies with Cryptography
Manjari Lal
Operating Systems
Cryptography is a branch of mathematics based on the transformation of data. It provides an important tool for protecting information and is used in many aspects of computer security. For example, cryptography can help provide data confidentiality, integrity, electronic signatures, and advanced user authentication. One of the best ways to obtain cost-effective data confidentiality is through the use of encryption. Encryption transforms intelligible data, called plaintext, into an unintelligible form, called cipher text. This process is reversed through the process of decryption. In this way Cryptography can be used for data encryption. 6. Command Interpretation Command Interpretation module of an operating system provides a set of commands using which users give instructions to a computer for getting their jobs processed. It provides a user interface to hide hardware details of a system from its users. The two broad categories of user interfaces supported by various operating systems are: 1. Command-line Interface (CUI): Users give instructions to computers by typing commands in this character user interface. For example in UNIX and MS-DOS, a user has to type a command to get work done from the system. If a user types a command incorrectly, command interpreter responds with a message indicating that it did not understand the command. 2. Graphical User Interface (GUI): It is much easier to learn and use than command-line interface, GUI commands are graphical (pictorial). GUI provides a screen full of graphic icons, or menus to users, and allows rapid selection from displayed icons or menus to give instructions to computers. A point-and-draw device (e.g. a mouse) is used normally to rapidly point to and select a particular icon.
Terminology explained: Multiprogramming: When there are a number of jobs on the disk which are ready to be executed / processed, the operating system has to choose a job from the job pool that is to be executed. Job scheduling brings in the ability of multiprogramming. A single user cannot keep both CPU and I/O devices busy. Multiprogramming increases CPU utilization by organizing jobs in a manner such that CPU always has a job to execute. The operating system picks and executes one of the jobs in memory. When the job in execution needs an I/O operation to complete, it moves to the I/O device and the CPU becomes idle. Instead of waiting for the job to complete the I/O, the CPU switches to another job in memory. When the previous job has completed the I/O, it joins the subset of jobs waiting for the CPU time. As long as there are jobs in memory waiting for the CPU, the CPU is never idle. Choosing one out of several ready jobs in memory for execution by the CPU is called CPU scheduling. Multiprogramming is interleaved execution of two or more different and independent programs of multiple users in a multi-user system Multitasking: Technically speaking multitasking is same as multiprogramming. But the term multiprogramming is used for multi-user systems (systems that are used simultaneously by many users), and multitasking for single user systems (systems that are used by only one user at a time such as personal computer or a notebook computer). In a single user system also there may be multiple tasks being processed simultaneously. While the user is working on one application, another application can be running in the background. An Operating System achieves this effect by rapidly switching tasks, by scheduling the Microprocessor to work on more than one task at the same time. The Microprocessor alternates so quickly from task to task that the user might think the machine is processing several jobs at the same time. Time -sharing systems:
Manjari Lal
Operating Systems
Interactive jobs need on-line communication between the user and the system. Time-sharing / multitasking is a logical extension of multiprogramming. It provides interactive use of the system. It allows many users to share the system simultaneously. CPU scheduling and multiprogramming provide each user one time slice (slot) in a timeshared system. A program in execution is referred to as a process. The short period during which a user process gets to use the CPU is known as time-slice / time-slot. A process executes for one time slice at a time. A process may need more than one time slice to complete. The CPU is taken away from a running process when the allotted time slice expires. During a time slice a process may finish execution or go for I/O. The I/O in this case is usually interactive like a user response from the keyboard or a display on the monitor. The CPU switches between processes at the end of a time slice. The switching between processes is so fast that the user gets the illusion that the CPU is executing only one users process. Multiprocessor systems: Multiprocessor systems are also known as parallel systems or tightly coupled systems. These systems have more than one processor in close communication sharing the bus, clock, memory and peripheral devices. The main advantages of multiprocessor systems are: 1. Increased throughput: increase in the number of processors means more work in less time. 2. Economical: multiprocessor systems are economical as they save money. This reduced cost is due to resource sharing. 3. Increased reliability: as the name implies, availability of more than one processor increases reliability. Failure of one processor will not bring activity to a standstill, although there may be a slowdown. This is referred to as graceful degradation and systems which are designed to provide graceful degradation are also called fault tolerant systems. Multiprocessor systems use either synchronous multiprocessing or asynchronous multiprocessing. In synchronous multiprocessing, each processor runs the same copy of the operating system. All processors are peers. The advantage here is that n processes can be executed simultaneously if there are n CPUs. In asynchronous multiprocessing, each processor is assigned a specific task. A master process controls the system. The other processes look up to the master for instructions or tasks to execute. A master-slave relationship is thus defined and job scheduling is the work of the master. Based on the relationships between processes and memory, multiprocessor systems can be classified as: 1. Tightly-coupled: individual processors within the multiprocessor system share Global shared memory. 2. Loosely-coupled: individual processors within the multiprocessor system access their own private / local memory. This classification may not be very rigid and multiprocessor systems have both shared memory as well as local memory. Virtual memory: Processes whose memory requirement is larger than the maximum size of the memory available may never be able to execute, but virtual memory is a technique that allows execution of processes that may not be entirely in memory. It also raises the degree of multiprogramming and increases CPU utilization. Because of the above features, users are freed from worrying about memory requirements and availability. Need for virtual memory technique: Every process needs to be loaded into physical memory for execution. A process cannot be loaded until sufficient free memory for loading the entire process becomes available or a process cannot be loaded in a system whose main memory size is less than the total memory required by the process. When a process is to be executed then only that page of the process, which needs to be currently executed, is swapped into memory. Three basic concepts for realization of virtual memory are: 1. On-line secondary storage:
Manjari Lal
Operating Systems
2. Swapping: Swapping is the process of transferring a block of data from on-line secondary storage to main memory or vice-versa. When data is transferred from on-line secondary storage to main memory, it is called swapping in of data, and when data is transferred from main memory to on-line secondary storage, it is called swapping out of data. 3. Demand Paging: All processes are partitioned into pages and reside on the on-line secondary storage. The physical memory is also partitioned into page frames of the same size. Instead of loading an entire process before execution, a swapping algorithm (called demand paging) is used that swaps in those pages of the process that are currently needed in memory for its execution to continue. When there is no free page in memory, a page residing in memory but not being used currently is swapped out to free the page frame it is occupying. The concept of Virtual Memory is just a practice of using a hard drive to fool the operating system and application into behaving as if there was more Random Access Memory than actually exists. Real Time Operating System A Real Time Operating System or RTOS is an operating system that has been developed for real time applications, typically used for embedded applications. Real-time and embedded systems operate in constrained environments in which computer memory and processing power are limited. They often need to provide their services within strict time deadlines to their users and to the surrounding world. It is these memory, speed and timing constraints that dictate the use of real-time operating systems in embedded software. Real-time and embedded systems are used in many applications such as airborne computers, medical instruments and communication systems. Real-time requirements impose stringent time deadlines for delivering the results of embedded processing. RTOS kernels hide from application software the low-level details of system hardware, and at the same time provide several categories of services to application software. The issue of timing determinism is important in differentiating general-computing operating systems from real-time operating systems. A real-time operating system (RTOS) is an operating system that guarantees a certain capability within a specified time constraint. For example, an operating system might be designed to ensure that a certain object was available for a robot on an assembly line. In what is usually called a "hard" realtime operating system, if the calculation could not be performed for making the object available at the designated time, the operating system would terminate with a failure. In a "soft" real-time operating system, the assembly line would continue to function but the production output might be lower as objects failed to appear at their designated time, causing the robot to be temporarily unproductive. Some real-time operating systems are created for a special application and others are more general purpose. Real-time operating systems are often required in small embedded operating systems that are packaged as part of micro devices. Embedded system An Embedded system is a special-purpose computer system usually built into a small device. An embedded system is required to meet different requirements compared to general-purpose personal computers. It has a processor and specific supporting devices and a compact operating system. These components are just adequate to meet the specific application for which it is designed. In general, an embedded system is a device meant for a specific application. It is a small compact micro computer which performs a specific job. Embedded systems are being used in almost all fields such as: Consumer Electronics Office Automation Industrial Automation Medical Electronics Computer Networking Telecommunications Wireless technologies Instrumentation Security Finance
Manjari Lal
Operating Systems
Specific examples of embedded systems Automatic teller machines (ATMs) Cellular telephones and Telephone switches Computer network equipment, including Routers, Switches and Firewalls Computer printers Disk drives (floppy disk drives and hard disk drives) Engine controllers and antilock brake controllers for automobiles Home automation products, like thermostats, air conditioners, sprinklers, and security monitoring systems Handheld calculators Household appliances, including microwave ovens, washing machines, television sets, DVD players/recorders Inertial guidance systems, flight control hardware/software and other integrated systems in aircraft and missiles Medical equipments, BP monitor, Sugar level monitor etc Measurement equipment such as digital storage oscilloscopes, logic analyzers, and spectrum analyzers Multifunction wrist watches Personal Digital Assistants (PDAs), i.e. small handheld computers Programmable logic controllers (PLCs) for industrial automation and monitoring Stationary videogame consoles and handheld game consoles Two major areas of differences are cost and power consumption. Since many embedded systems are produced in the tens of thousands to millions of units, reducing cost is a major concern. Embedded systems often use a (relatively) slow processor and small memory size to minimize costs. The slowness is not just clock speed. The whole architecture of the computer is often intentionally simplified to lower costs. Firmware is the name for software that is embedded in hardware devices, e.g. in one or more ROM / Flash memory IC chips. Embedded systems are routinely expected to maintain 100% reliability while running continuously for long periods. Firmware is usually developed and tested to much stricter requirements than is general purpose software which can usually be easily restarted if a problem occurs. Differences between desktop/laptop computer and embedded system: A desktop or a laptop computer is a general purpose computing device. We can use this for variety of applications such as computing, playing games, word processing, software development and so on. The general purpose computer permits addition of new compatible software tools for application development. However the embedded system differs from the laptop/desktop computers in the following ways Embedded systems do a particular job. They cannot be programmed to do different jobs. Embedded Systems have very limited resources, especially memory. They have only semiconductor memory. Secondary memories such as hard disk or compact disk are not available. Most of the embedded systems work in real time, i.e., the tasks are usually time synchronized. Embedded systems normally operate on the battery. So power consumption is highly optimized and hence their hardware has high impact on the power consumption. Embedded systems are to be highly reliable. There is no compromise on this.
Manjari Lal