d. Hardware protection
To improve the resource utilization, the operating system shares the resources among different programs simultaneously. This resources sharing can cause problems as many processes could be affected by a bug in one program. In a multiprogramming system one erroneous program might modify another program data. The operating system has to be deigned to ensure that an erroneous program cannot cause other programs to execute incorrectly.
i. Dual-mode operation
When a resource sharing is used, the operating system protects the programs using two separate modes of operation:
- User mode: when a task is executed on behalf of the user.
- Monitor mode (also called supervisor mode, system mode, or privileged mode): when a task is executed on behalf of the operating system.
To indicate the current mode, a bit, called the mode bit, is used. When the system starts, the operating system gains control of the system and it is in monitor mode (the mode bit is 0). When the use program starts, the system is in user mode (the mode bit is 1). Whenever a trap or interrupt occurs, the hardware switches from user mode to monitor mode (Silberschatz et.al., (2008)).