What is an Operating System?

  • Post author:
  • Post last modified:May 2, 2024
  • Reading time:14 mins read

An operating system is, conceptually, a layer of software residing just above the hardware and below all other software layers. It hides the intricate details of hardware resources like processor, memory, secondary storage and input and output devices and provides corresponding simple, intuitive, abstract resources. An operating system is also a resource manager, managing the hardware resources of a computer.

1. A Computer System

Computer system

A computer system comprises of hardware and software. A very important software in a computer system is its operating system. Conceptually, as shown in the figure above, an operating system is a layer of software that resides just over the hardware. There might be more layers of system and application software on top of the operating system. The operating system hides the complexity of hardware and presents a intuitive, coherent, easy to use interface for using the computer. Most of the times, the term operating system refers to the operating system kernel, which encompasses the hardware and provides the system call application programming interface (API) to the software layers coming after it. Then, there are system programs for jobs like running a program on the computer, creating and managing files, taking backups, etc. which are often clubbed with the kernel to make the operating system. But there is nothing magical about these system programs and these can always be written using the system calls by anyone. In the rest of this post, we will refer to the kernel when we use the term “operating system”.

In the figure shown above, the kernel is the only truly distinct layer on top of the hardware. The system programs and libraries share a fuzzy boundary with outer software layers. In fact, some higher level software layers might implement their own lower level layers using the kernel’s system call interface.

An operating system does two things. The first is resource abstraction. The operating system hides the intricate details of hardware from the higher layer software and presents a nice, elegant and easy to use interface in terms of system calls, the API for using the computer. Second, it is the resource manager for the computer. It combines and uses the hardware resources in such a way that objectives like “response time should be less” and/or “the throughput of the computer should be high” are met to the maximum extent possible.

2. Resource Abstraction

Operating systems provide abstraction of hardware resources for higher layer software programs. Hardware resources like processor, main memory, communication devices, persistent storage devices, etc are inherently complex. It is practically impossible for application programmers to write programs which implement the application logic and also to generate instructions for exercising the hardware devices. The operating system hides the intricate hardware details and provides simple, intuitive and easy to use abstractions. These abstractions are further refined and provided as the system call API, which can be used by higher layer application programs. Effectively, the operating system provides a virtual machine which appears to be running just the operating system (kernel and system programs) to higher level application software programs.

3. Process

The job of a computer is to run programs. The operating system provides an abstraction named “process”, which runs a program. There are a number of “live” processes in the operating system, which appear to be progressing concurrently at any time. The fork system call creates a process. Then, there is the exec family of calls, using which we can make a process execute a given program. Multiple concurrent process can execute the same program using an exec call. However, these processes have no relationship with one another. Each process has independent address space, comprising of code, data and system data segments. The operating system provides calls for communication between processes and for synchronization of processes.

By default, a process has a single thread of execution. There is the pthreads library which can be used for having multiple threads of execution for a process. These threads share the data segment of the underlying process but have independent stacks. pthreads also provides calls for synchronization of threads.

4. Virtual memory

A computer has physical main memory, which is simply a sequence of bytes. The operating system provides virtual memory which is much larger than the physical memory. The operating system uses secondary storage along with the main memory and “intelligently” shuffles parts of main memory to secondary storage and vice-versa to keep the operations going. Each process gets its private address space which is protected from access by other processes. The addresses in the virtual address space are virtual addresses. The programs work using the virtual addresses. The virtual addresses are converted into physical addresses during execution by the memory management unit. Since the virtual address space is bigger than the physical memory and there are multiple processes resident in the memory at any time, there would be parts of the processes’ address space that are not resident in the main memory at that time. So, while executing an instruction, the memory management unit might realize that a required operand is not in the physical memory and the concerned part of the memory needs to loaded from the secondary storage to the main memory to execute the instruction. A trap, similar to an interrupt, is generated and the operating system loads the relevant data from the secondary storage to the main memory and the instruction is executed.

The advantages of virtual memory are that a process gets a large, private and protected address space and the program can use virtual addresses for accessing memory locations. The operating system and the memory management unit work together to make this possible.

5. Concurrency

An operating system makes it possible for a computer to do many things at a time. Multiple jobs progress in the computer concurrently. A computer system can be used by multiple users at a time and these users can also execute multiple programs at any time. The programs run as processes which co-exist in the system and progress concurrently. This requires handling of a host of problems. For example, multiple processes might want to write to the hard disk at a time. The kernel employs multiple techniques to handle this. The file system uses locks to control access to files and directories. The kernel uses schedulers to schedule I/O operations. The I/O operations are queued and the queue is serviced. The kernel maintains buffers and the write is first done to buffers and the buffers are synced to the hard disk after some time. The system might also support atomic write operations, where either the write is done completely or nothing is done.The kernel also uses locks, semaphores and other synchronization mechanisms.

By default, a process has a single thread of execution, and if the application software has been designed as single program with a single thread of execution, then the programmer need not worry about concurrency. The operating system takes care of access to shared resources like I/O devices. But, quite often, the software is designed as having multiple threads of execution. It might have multiple processes and some of the processes might have multiple threads. So, the designers have to take care of concurrency issues. For example, there might be critical data that can only be accessed by one process at a time. Some of the processes, called producers, produce data which is processed by other processes, called consumers. The producers and consumer processes need to be synchronized; the consumers can only work after producers produce some data. Some processes might need some information form others; they work with the request-reply mode of communication. How does an operating system help in these scenarios? The operating system provides mechanisms for communication and synchronization between processes. The operating system provides pipes, fifos, message queues and shared memory mechanisms for communication between processes and semaphores for synchronization of processes. Similar to processes, threads provide concurrent threads of execution inside a process. However, since threads share the global data of the process they belong to, there is no need for special mechanism for communication between threads. However, threads need to be synchronized. The operating system provides the mutex object, which is short for mutual exclusion, and using which a thread can access a critical section (data or code) exclusively. The operating system also provides condition variables, which help a thread in waiting for certain conditions becoming true.

6. Persistence

Computers deal with data, which is processed and, after processing, it becomes useful information. Most importantly, computers need to to store data. The data in the main memory, RAM, is lost when the power is switched off. Also, the data in the main memory is not directly available to the users. The users just can not simply look at the contents of RAM; they need a special program for doing so. (Even with a special program it is difficult to interpret the contents of RAM, as the operating system does not provide an abstraction for that.) So it is important that computers store data which is persistent, that is, it stays constant across system boot and shutdown cycles and that can used easily by the users. Traditionally, data has been stored on the hard disk in the system. Now-a-days solid-state drives (SSDs) are becoming increasingly common and provide a faster and more reliable medium for persistent storage. These devices storing data permanently are known as secondary storage devices.

The hardware interfaces and other details of secondary storage devices are inherently complex. The operating system manages theses devices. It has programs known as device drivers and these programs do the actual input and output operations on the secondary storage devices. (There are device drivers for other devices also, like the drivers for network interface cards, or the drivers for audio devices like mic and speakers.) The operating system provides simple, intuitive abstractions like files and directories or folders for storing files on the secondary storage. The directories are organized in the form of an inverted tree, where the root directory is at the top and other system and user directories below it. A directory may contain files and other directories. The operating system provides API functions or system calls for creating directories and files, reading and writing data to these files, deleting files, traversing a directory tree, etc. The key point is that the operating system provides a layer of software over the complicated and involved hardware devices and provides a simple, intuitive, easy to use interface for users and application programs.

7. Input and Output

A computer needs to interact with the external world. It does so by doing input and output operations. All computing involves taking inputs, processing it, storing information and giving outputs in the form of reports, web pages, audio and video outputs, etc. Computers need to communicate with other hosts on the local network and the Internet. All this involves interacting with input and output devices. These devices are intricate and, although there is standardization of interfaces to some extent, there are differences, especially in video output monitors, high end communication interfaces, and also some audio devices that can be connected over the USB. To summarize, the devices are complex and whether a device is compatible with an operating system or not, is often an issue. But overall, operating systems take care of the complexity, freeing a user (and programs) from the difficult task of doing I/O directly on a device. So, “system” programs are available to users for connecting modems, audio and video devices, tablets, smartphones, mice, laser printers, plotters, scanners, etc. Also, the standard read and write system calls can be used for input and output operations on these devices. For network communications, there is the socket interface which works seamlessly over network interfaces and remote communication can be done by using protocols like User Datagram Protocol (UDP) and Transmission Control Protocol (TCP), which are a part of the operating system.

8. Resource Manager

The foregoing discussion of viewing the operating system as a virtual machine is essentially a top-down viewpoint. And, as you would have imagined, there is bottom-up point of view as well. An operating system is a resource manager. Each of the hardware building blocks, like the CPU, memory, secondary storage, I/O devices, is a resource and needs to be used in an optimal way in order to meet certain objectives. These objectives can be like good response time for users, maximizing the throughput, fair allocation of resources ensuring that there is no starvation of a resource for any user (a user is, generally, a process), ensuring a good predetermined network speed, etc.

The resources in a computer system are scarce and the demand is high. For example, a system might have a single processor and a hundred-odd processes, out of which, say, a 10-odd might be ready to run and vie for the processor at a time. The operating system must choose one out of these ten processes to use the processor next. These 10-odd processes form the “ready queue”, the queue of processes ready to run. How is this queue ordered? It is a matter of policy. The queue might be ordered first-in first-out and the operating system might take the process at the head of the queue out, run it for a fixed time slice or less if the process relinquishes the CPU earlier voluntarily. Then, it it is still ready to run, it could be placed at the end of the “ready to run” queue. The operating system is essentially multiplexing the CPU between multiple processes which are ready to run. Here, the CPU is time multiplexed as each process in the queue uses it for the time slice or less.

Instead of time multiplexing, a resource might be space multiplexed. That is, instead of processes taking tuns of using the resource, a part of the resource could be given to each process. This happens in the case of virtual memory. A part of the main memory is given to each process so that it partly stays in the main memory and the rest of the process’s address space is kept on the secondary storage. This is managed entirely by the memory management unit and the operating system; the process is only aware of its virtual address space. Similarly, the hard disk is space multiplexed. A small part of the hard disk resource is given to each user. The operating system keeps track of the location of files and it also manages the free space, that is, it knows where to write data, when a process wants to do a write operation on it.

9. Conclusion

An operating system provides abstraction of hardware resources, making it easier to build application programs. An operating system is also a resource manager, managing the computer hardware resources and meeting overall system objectives.

Share

Karunesh Johri

Software developer, working with C and Linux.
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments