1 Operating-System Structure

As we already know that, an operating system provides the environment within which programs are executed. One of the most important aspect of operating system is the ability to multiprogram. Single user frequently have multiple programs running.

1.1 Multiprogramming

Multiprogramming increases the CPU utilization by organizing jobs (code and data) so the CPU always has one to execute. The idea is as follows:

  1. Operating system keeps several jobs in the memory simultaneously.

  2. Since, main memory is too small to accommodate all jobs, the jobs are kept initially on the disk in the job pool. This pool consists of all processes residing on disk awaiting allocation of main memory.

  3. Operating system picks and begins to execute one of the jobs in memory. Eventually, if that job have to wait for some task, the CPU switches to another job, and so on.

  4. Eventually, the first job finishes waiting and get the CPU back. As long as at least one job needs to execute, the CPU never idle.

Multiprogrammed systems provide an environment in which the system resources are utilized efficiently, but they don’t provide for user interaction with the computer system.

1.2 Multitasking / Time Sharing

Multitasking is a logical extension of multiprogramming. In time-sharing systems, the CPU executes multiple jobs by switching among them, but switches occur so frequently that the users can interact with each program while it is running.

Time sharing required an interactive computer system, which provides direct communication between the user and the system.

Time sharing operating system uses CPU scheduling and multiprogramming to provide each user with a small portion of a time-sharing computer. Each user has at least one separate program in memory.

A program loaded into memory and executing is called process.

1.3 Terminologies

Time sharing and multiprogramming require some proper algorithms to make user as well main memory happy.

  • Job scheduling ~> Selecting a job from job pool so that it loads that job into memory for execution while keeping enough room in the memory for other jobs.

  • Memory management ~> Having several programs in memory at the same time requires a proper management system.

  • CPU scheduling ~> If several jobs are ready to run at the same time, the system must choose which job will run first.

  • Virtual memory ~> A common method of maintaining reasonable response time that allows the execution of a process that is not completely in memory. The virtual memory scheme enables users to run programs that are larger than actual physical memory.

2 Operating system Operatioins

We can say that, modern operating systems are interrupt driven. A trap (or an exception) is a software-generated interrupt caused either by an error (like, division by zero or invalid memory access) or by a specific request from a user program.

In time sharing system, many processes could be adversely affected by a bug in one program. Let’s say, if a process gets stuck in an infinite loop, this loop could prevent the correct operation of many other processes.

In multiprogramming system, where one erroneous program might modify another program, the data of another program, or even the operating system itself.

2.1 Dual-mode and Multimode Operation

In order to ensure the proper execution of the operating system, we must be able to distinguish between the execution of operating system code and user defined code.

Here we separate modes of operation into 2 parts.

  • User mode
  • Kernel mode (also called supervisor mode, system mode or privileged mode)

A bit, called mode bit, is added to the hardware of computer to indicate the current mode: kernel (0) or user (1). By using mode bit, we can distinguish between a task that is executed on behalf of the operating system and on behalf of a user application.

An user application can enter into kernel mode via system call to fulfill the user’s request.

There is another mode that exists between kernel and user modes for the CPUs that support virtualization. Virtualization management software has more privileges than user processes but fewer than the kernel.

2.2 Timer

At every point, we must ensure that the operating system maintains control over the CPU. We can’t allow a user program to get stuck in an infinite loop or to fail to call system services and never return control to the operating system. Now to accomplish this goal, we can use a timer. A timer can be set to interrupt the computer after a specified period. The period may be fixed (1/60 sec) or variable (1ms to 1s).

A variable timer is generally implemented by a fixed-rate clock and a counter.

The operating system sets the counter. Every time the clock ticks, the counter is decremented. When the counter reaches 0, an interrupt occurs.

3 Questions

  1. What do you mean by ‘Multiprogramming’?

  2. What do you mean by ‘Multitasking’ system?

  3. State the differences between multiprogramming and time-sharing operating system.

  4. What do you mean by a ‘Process’?

  5. What do you mean by a ‘Trap’?

  6. How does an ‘exception’ cause problems in a multitasking and multiprogramming systems?

  7. What do you mean by ‘modes of operation’?

  8. Why ‘mode bits’ are added to modes?

  9. Virtualization management software works on ___________.

  1. Kernel mode
  2. User mode
  3. In between user and kernel mode
  4. Under user mode
  1. What is the mode bit for ‘Kernel’?

  2. Briefly describe ‘Timer’.