OSC 2 Introduction To Operating System Concepts Continued
OSC 2 Introduction To Operating System Concepts Continued
Concepts (Continued)
Operating System
Operations
Operating System Operation
• An operating system provides the environment within which programs are executed.
• For a computer to start it needs to have an initial program to run first. This program is
called a bootstrap program.
o A bootstrap program is different from a bootloader. The bootstrap program is a
small piece of code that resides in the ROM or other non-volatile memory or the
firmware of the computer.
▪ This is automatically loaded by the processor when the computer is turned on.
▪ It's main function is to load the bootloader from the disk or other storage device
into the memory.
Operating System Operation
• Once the operating system kernel is loaded into memory it can start providing
service to the users.
• Some services are provided outside of the kernel by the system programs that are
loaded into memory at boot time becomes system daemons.
o System daemons are also known as background processes, these processes run
in the background of an operating system performing specific tasks.
o Daemon stands for "Disk And Execution MONitor".
o These are programs that runs continuously in the background to handle system
chores, like handling processes of a specific device like Blutooth connectivity.
Operating System Operation
• After the operating system is fully booted, that is the kernel is loaded into memory
and the system daemons are running, then the system will simply go into a wait state
waiting until an event occurs.
• Events are usually triggered by an interrupt.
o In the previous slides we discussed hardware interrupts but there are other forms
of interrupt and one of them is called a trap (or an exception).
▪ Traps or exceptions are software-generated interrupts caused either by an error
(e.g., null pointer exceptions, and zero division)
▪ They can also be generated by a specific request from a user program that an
operating system service be performed by executing a special operation called
system call.
Multiprogramming and multitasking
• One of the most important aspect of an operating system is that it allows us to run
multiple programs simultaneously.
• If only a single program is allowed to run on our computer, then when the
programs reaches a point where it has to wait for a process to finish then the processor
would remain idle during that time.
o Keeping the utilization rate of the processor high means that the processor is
performing more task and using its resources efficiently.
▪ This can improve the performance and speed of the system, as well as reduce the
energy consumption and cost.
o Although ensuring that the utilization rate of a CPU is high is good, keeping it high for
too long could also result in problems such as overheating, system slowdowns, or
crashes.
Multiprogramming and multitasking
• Having multiple processes in the memory at the same time requires some form of
memory management.
• In addition to implementing memory management, the operating system also has to
ensure that, in case two or more processes are ready, it knows which process it
should prioritize. This is done using CPU Scheduling.
o There are different scheduling algorithm that is used by an operating system in
setting the prioritization of processes. This include, but is not limited to, first-
come first-served, round robin, Shortest Job First (SJF), Longest Job First (LFJ), etc.
Multiprogramming and multitasking
• A virtual memory is used to ensure that in a multitasking system the operating system remains
responsive even if there are multiple processes running concurrently.
o Virtual memory is a technique that allows the execution of a process that is not completely in
memory.
o This technique allows users to execute/run programs that are much larger compared to using
the physical memory.
o In addition, it abstracts the main memory into a large, uniform array of storage, separating the
logical memory as viewed by the user from the physical memory.
▪ This simply means that the operating system creates a way of organizing the memory
differently from how the actual memory is actually arranged in the hardware.
▪ This makes it easier for programmers since they don't have to worry about memory-storage
limitations allowing them to use more memory than the hardware allows.
Dual Mode and Multimode Operations
• The operating system switches mode using a special bit called the mode bit.
A mode bit is added to the hardware of a computer to indicate the current mode. If the
bit is 0 then the operating system is currently in kernel mode, if it is 1, the operating
system is in user mode.
▪ Typically, when the operating system boots up, it starts in kernel mode to load all the
necessary components of the OS and the OS itself, after that it transitions to user
mode and stays in that mode until a system call is performed.
• The mode always transitions to user mode before handing back control to the user
application.
o There are other mechanisms that are used to change the mode of an operating system
such as trap instructions or hardware interrupts.
Dual Mode and Multimode
Operations
Dual Mode and Multimode Operations
• The user process is executing in user mode, which is a restricted mode that prevents the
process from accessing protected memory or devices. The mode bit is 1, indicating user
mode.
• The user process calls a system call, which is a predefined function that the operating
system provides. This triggers a trap, which is a special instruction that transfers the
control to the kernel. The mode bit is changed to 0, indicating kernel mode.
• The kernel, which is the core part of the operating system, executes the system call on
behalf of the user process. The kernel has full access to the memory and devices, and
can perform the requested task.
• The kernel returns from the system call, and restores the control to the user process. The
mode bit is changed back to 1, indicating user mode. The user process resumes its
execution.
Dual Mode and Multimode Operations
• The dual mode of operations provides us the means for protecting the operating
system from errant users and errant users from one another.
• This protection is achieved through the use of privileged instructions – these are
machine instructions that may cause harm to the system by modifying the state of
the hardware such as issuing I/O commands, modifying the mode bit,
and accessing memory management unit.
o The system's hardware only allow privileged instructions to be executed in kernel
mode. This prevents users and user applications from causing potential harm to
the system.
Timer
• The timer is used to ensure that ensure that the user program doesn't monopolize the
CPU.
• In order to do that, the timer interrupts a computer after a fixed or variable time
period.
o For example, using fixed time period we can say that the operating system interrupts the CPU after
1/60 of a second.
o On other hand, using variable time, we can set how long the process should utilize the CPU before
being interrupted to allow the CPU to execute other processes.
• If there is no timer, a single process would monopolize the CPU and prevent
other processes from running.
o This would cause the system to become unresponsive, slow, or unstable.
o The timer ensures that the CPU is shared among multiple processes.
Resource
Management
Resource Management
• A program can't do anything if its instructions are not executed by the CPU.
• As mentioned in the previous discussion, the term process refers to a program that is
being executed.
• Programs such as compilers, word processors, social media apps, etc., being run by
users are examples of processes.
o Although this definition of process is not accurate as there is more to processes in general.
• A process is an instance of a computer program that is being executed by one or
more threads.
o It contains the program code and its current activity.
Process Management
• A process needs resources such as CPU time, memory, and I/O devices to
accomplish its task.
o This resources are typically allocated to the process during its execution.
o In addition to those resources, there could be other resources that a process needs, this
includes physical(hardware) and logical(software) resources that it obtains when the process is
created.
▪ This also include inputs from users.
o After the process finished executing, the operating system reclaims the resources allotted to the
process during its execution.
Process Management
• A single-threaded process has one program counter specifying the next set of
instructions that should be executed.
o A program counter, also known as instruction pointer or instruction counter, is a register in the CPU
that contains the address of the next instruction to be executed from memory.
▪ Basically, a program counter is like a pointer that tells the processor which instruction that is currently stored in the memory it
should execute next.
o The execution of a process should be sequential.
o The CPU executes a one instruction of the process until the process is completed.
▪ If the process is interrupted (e.g., an error is encountered) the current value of the program counter Is saved so that the
execution can resume from the correct point when the process is restarted.
Process Management
• The file system provides a user-friendly interface that can be used to get a logical view
of information storage.
• This abstracts away the physical properties of its storage devices to define a
logical storage unit, the file.
o It abstracts away the complexities of physical storage by mapping file(s) from onto physical media
and accesses this files via storage devices.
• A file is a collection of related information defined by its creator.
o Commonly, files represent programs (both on its source and object forms) and data.
▪ Data files may be numeric, alphabetic, alphanumeric, or binary.
o Files may be free-form (e.g., text files) or have a defined format (e.g., audio files, markup files,
and videos).
Mass Storage Management
• Most modern systems use either an HDD or an NVMe devices as the primary way of
storing programs and data.
• The operating system is responsible for managing the storage of a computer, and this
typically involve:
o Mounting and unmounting. Ensure that the file system is properly prepared for the use (mounted) before
any access to the data it contains and also ensure the the FS is properly disconnected (unmounted) when no
longer needed.
o Managing free disk space. The OS should know how much free space there is in the disk.
o Storage allocation. The OS should abstract away the complexity of storing a file/data/program.
o Disk scheduling. This is also known as I/O scheduling. Manage and schedule I/O requests arriving for the
disk.
o Partitioning. The OS should provide the capability to divide a physical disk into one or more logical
disks/partitions. Each disk functions as if they were a separate disk.
o Protection. Ensure that proper authentication and authorization is applied to the access of the mass
storage.
Resources