0% found this document useful (0 votes)
12 views85 pages

OS YouTube

An operating system (OS) is essential software that manages computer hardware and provides services for programs, including file, memory, and process management. It ensures security, system performance, and communication between software and users. The document also outlines various OS functions, services, and types, such as batch and real-time operating systems.

Uploaded by

yahyaomar2210
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views85 pages

OS YouTube

An operating system (OS) is essential software that manages computer hardware and provides services for programs, including file, memory, and process management. It ensures security, system performance, and communication between software and users. The document also outlines various OS functions, services, and types, such as batch and real-time operating systems.

Uploaded by

yahyaomar2210
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 85

Operating Systems

Chapter 1: Introduction to Operating Systems


Back Next
Introduction
● An operating system (OS) is a collection of software that manages computer hardware resources and provides
common services for computer programs.

● The operating system is a vital component of the system software in a computer system.

● Why to Learn Operating System?


An Operating System (OS) is an interface between a computer user and computer hardware.
An operating system is a software which performs all the basic tasks like file management, memory management,
process management, handling input and output, and controlling peripheral devices such as disk drives and printers.

Back Next
Applications of Operating System
● Following are some of the important activities that an Operating System performs −

● Security − By means of password and similar other techniques, it prevents unauthorized access to programs and
data.

● Control over system performance − Recording delays between request for a service and response from the
system.

● Job accounting − Keeping track of time and resources used by various jobs and users.

● Error detecting aids − Production of dumps, traces, error messages, and other debugging and error detecting
aids.

● Coordination between other software's and users − Coordination and assignment of compilers, interpreters,
assemblers and other software to the various users of the computer systems.

Back Next
Operating Systems Functions
An operating system is a program that acts as an interface between the user and the computer hardware and controls
the execution of all kinds of programs.

Back Next
Operating Systems Functions
● Process management:- Process management helps OS to create and delete processes. It also provides mechanisms
for synchronization and communication among processes.

● Memory management:- Memory management module performs the task of allocation and de-allocation of
memory space to programs in need of this resources.

● File management:- It manages all the file-related activities such as organization storage, retrieval, naming, sharing, and
protection of files.

● Device Management: Device management keeps tracks of all devices. This module also responsible for this task is
known as the I/O controller. It also performs the task of allocation and de-allocation of the devices.

● I/O System Management: One of the main objects of any OS is to hide the peculiarities of that hardware devices from
the user.

● Secondary-Storage Management: Systems have several levels of storage which includes primary storage, secondary
storage, and cache storage. Instructions and data must be stored in primary storage or cache so that a running program
can reference it.

Back Next
Operating Systems Functions
● Security:- Security module protects the data and information of a computer system against malware threat and
authorized access.

● Command interpretation: This module is interpreting commands given by the and acting system resources to
process that commands.

● Networking: A distributed system is a group of processors which do not share memory, hardware devices, or a
clock. The processors communicate with one another through the network.

● Job accounting: Keeping track of time & resource used by various job and users.

● Communication management: Coordination and assignment of compilers, interpreters, and another software
resource of the various users of the computer systems.

Back Next
2.1 Memory Management
● Memory management refers to management of Primary Memory or Main Memory.
● Main memory is a large array of words or bytes where each word or byte has its own address.

● Main memory provides a fast storage that can be accessed directly by the CPU.

● For a program to be executed, it must in the main memory.

An Operating System does the following activities for


1. Keeps tracks of primary memory, i.e., what part of it are in use by whom, what part are not in use.
2. In multiprogramming, the OS decides which process will get memory when and how much.
3. Allocates the memory when a process requests it to do so.
4. De-allocates the memory when a process no longer needs it or has been terminated.

‫ إذا قام‬.‫ يتم تخصيص مساحة من الذاكرة العشوائية لتخزين بيانات هذا البرنامج‬،‫ عندما يقوم المستخدم بتشغيل برنامج معين‬،‫على سبيل المثال‬ ●
.‫ يتم تخصيص مساحات من الذاكرة العشوائية لكل برنامج بحيث ال يتعارضوا مع بعضهم البعض‬،‫المستخدم بفتح عدة برامج في وقت واحد‬

Back Next
2.2 Processor Management
● In multiprogramming environment, the OS decides which process gets the processor when and for how much
time. This function is called process scheduling.

An Operating System does the following activities for processor management:


1. Keeps tracks of processor and status of process. The program responsible for this task is known as traffic controller.
2. Allocates the processor (CPU) to a process.
3. De-allocates processor when a process is no longer required

‫ فإن الجدول‬،‫ثوان‬
ٍ 10 ‫تريد استخدام المعالج لمدة‬B ‫ والعملية‬،‫ثوان‬
ٍ 5 ‫استخدام المعالج لمدة‬A ‫ إذا كان هناك عمليتان في النظام وتريد العملية‬،ً‫مثال‬
،‫ وبعد انتهاء وقت المعالجة المخصص لكل عملية‬.‫الزمني للمعالجة سيحتوي على تخصيص وقت المعالجة لكل منهما وفقًا ألولوياتهما واحتياجاتهما‬
.‫يتم تخصيص وقت المعالجة للعملية التالية في القائمة‬

Back Next
2.3 Device Management
● An Operating System manages device communication via their respective drivers.

It does the following activities for device management:


1. Keeps tracks of all devices. Program responsible for this task is known as the I/O controller.
2. Decides which process gets the device when and for how much time.
3. Allocates the device in the efficient way.
4. De-allocates devices.

:‫مثال على إدارة األجهزة في نظام التشغيل ويندوز‬ ●

‫ يمكن للمستخدم من خالل‬."‫ يتم اكتشاف الجهاز من قبل نظام التشغيل ويتم عرضه في قائمة "مدير األجهزة‬،‫بالحاسوب‬USB ‫عند توصيل جهاز‬ ●
.‫ وإدارته وتكوينه وتحديث برامج التشغيل الخاصة به‬،‫النقر على الجهاز في القائمة الحصول على معلومات مفصلة عن الجهاز‬

Back Next
‫‪2.4 File Management‬‬
‫●‬ ‫‪A file system is normally organized into directories for easy navigation and usage. These directories may contain files‬‬
‫‪and other directions.‬‬

‫‪An Operating System does the following activities for file management:‬‬
‫‪1.‬‬ ‫‪Keeps track of information, location, uses, status etc. The collective facilities are often known as file system.‬‬
‫‪2.‬‬ ‫‪Decides who gets the resources.‬‬
‫‪3.‬‬ ‫‪Allocates the resources.‬‬
‫‪4.‬‬ ‫‪De-allocates the resources.‬‬

‫على سبيل المثال‪ ،‬يتم تنظيم الملفات في القرص الصلب في أشكال مختلفة‪ ،‬مثل الحاويات والمجلدات‪ .‬يتم تخزين الملفات في األقسام‬ ‫●‬
‫المخصصة على القرص الصلب‪ ،‬ويمكن الوصول إليها من خالل تنظيمها بشكل مناسب‪.‬‬

‫عندما يتم تخزين الملفات‪ ،‬يتم تحديد حجم الملف‪ ،‬ووقت اإلنشاء‪ ،‬ونوع الملف‪ ،‬وغير ذلك من المعلومات المتعلقة بالملف‪ .‬وبعد ذلك‪ ،‬يتم تخزين‬ ‫●‬
‫هذه المعلومات في جدول الملفات الموجود في القرص الصلب‪.‬‬

‫وتستخدم العديد من العمليات في إدارة الملفات‪ ،‬مثل إنشاء ملف‪ ،‬وفتح ملف‪ ،‬وحفظ الملف‪ ،‬وإغالق الملف‪ .‬وتقوم العمليات المختلفة بإدارة‬ ‫●‬
‫الملفات بشكل مناسب‪ ،‬وتساعد على حفظ الملفات بشكل آمن وفعال في القرص الصلب‪.‬‬

‫‪Back‬‬ ‫‪Next‬‬
2.5 Other Important Activities
● Security − By means of password and similar other techniques, it prevents unauthorized access to programs and
data.

● Control over system performance − Recording delays between request for a service and response from the system.

● Job accounting − Keeping track of time and resources used by various jobs and users.

● Error detecting aids − Production of dumps, traces, error messages, and other debugging and error detecting aids.

● Coordination between other softwares and users − Coordination and assignment of compilers, interpreters,
assemblers and other software to the various users of the computer systems

Back Next
3. OS Services:
● An Operating System provides services to both the users and to the programs.
● It provides programs an environment to execute.
● It provides users the services to execute the programs in a convenient manner.

● Following are a few common services provided by an operating system:

1. Program execution
2. I/O operations
3. File System manipulation
4. Communication
5. Error Detection
6. Resource Allocation
7. Protection

Back Next
3.1 Program execution
● Operating systems handle many kinds of activities from user programs to system programs like printer spooler, name
servers, file server, etc. Each of these activities is encapsulated as a process.

● A process includes the complete execution context (code to execute, data to manipulate, registers, OS resources in
use).

Following are the major activities of an operating system with respect to program management:
1. Loads a program into memory.
2. Executes the program.
3. Handles program's execution.
4. Provides a mechanism for process synchronization.
5. Provides a mechanism for process communication.
6. Provides a mechanism for deadlock handling.

‫ويقوم المعالج بتنفيذ األوامر في‬RAM) ( ‫ يتم تحميل البرنامج من القرص الصلب إلى الذاكرة العشوائية‬.‫يتم إدخال برنامج على جهاز الكمبيوتر‬ ●
‫ وعند االنتهاء يتم حفظ البيانات النهائية على القرص الصلب‬،‫ يتم حفظ البيانات الوسيطة في الذاكرة العشوائية خالل تنفيذ البرنامج‬.‫عا‬
ً ‫البرنامج تبا‬
.‫ يتم إغالق البرنامج وتحرير الذاكرة العشوائية التي كان يستخدمها البرنامج‬،‫ في النهاية‬.‫لالحتفاظ بها‬

Back Next
3.2 I/O Operation
● An I/O subsystem comprises of I/O devices and their corresponding driver software.

● Drivers hide the peculiarities of specific hardware devices from the users.

● An Operating System manages the communication between user and device drivers.

1. I/O operation means read or write operation with any file or any specific I/O device.
2. Operating system provides the access to the required I/O device when required.

Back Next
3.3 File system manipulation
● A file represents a collection of related information. Computers can store files on the disk (secondary storage), for
long-term storage purpose.

● A file system is normally organized into directories for easy navigation and usage. These directories may contain files
and other directions

Following are the major activities of an operating system with respect to file management:
1. Program needs to read a file or write a file.
2. The operating system gives the permission to the program for operation on file.
3. Permission varies from read-only, read-write, denied and so on.
4. Operating System provides an interface to the user to create/delete files.
5. Operating System provides an interface to the user to create/delete directories.
6. Operating System provides an interface to create the backup of file system

Back Next
3.4 Communication
● In case of distributed systems which are a collection of processors that do not share memory, peripheral devices, or a
clock, the operating system manages communications between all the processes.

● Multiple processes communicate with one another through communication lines in the network.

Following are the major activities of an operating system with respect to communication:
1. Two processes often require data to be transferred between them
2. Both the processes can be on one computer or on different computers, but are connected through a computer
network.
3. Communication may be implemented by two methods, either by Shared Memory or by Message Passing

Back Next
‫‪3.5 Error handling‬‬
‫●‬ ‫‪Errors can occur anytime and anywhere. An error may occur in CPU, in I/O devices or in the memory hardware.‬‬

‫●‬ ‫‪Following are the major activities of an operating system with respect to error handling:‬‬
‫‪1.‬‬ ‫‪The OS constantly checks for possible errors.‬‬
‫‪2.‬‬ ‫‪The OS takes an appropriate action to ensure correct and consistent computing.‬‬

‫في حالة حدوث خطأ أثناء قراءة الملفات من القرص الصلب‪ ،‬يتم عرض رسالة خطأ تفيد بذلك وإيقاف تشغيل البرنامج‪.‬‬ ‫●‬

‫في حالة وجود صالحيات غير كافية لتنفيذ بعض األوامر‪ ،‬يتم عرض رسالة تفيد بذلك وإعطاء المستخدم خيارات لتعديل الصالحيات أو تسجيل‬ ‫●‬
‫الدخول بحساب آخر يملك الصالحيات الالزمة‪.‬‬

‫في حالة حدوث خطأ أثناء االتصال بشبكة اإلنترنت‪ ،‬يتم عرض رسالة تفيد بذلك وإعطاء المستخدم خيارات للتحقق من اتصاله بالشبكة وإعادة‬ ‫●‬
‫المحاولة الحقًا‪.‬‬

‫في حالة عدم وجود مساحة كافية على القرص الصلب لتخزين الملفات‪ ،‬يتم عرض رسالة تفيد بذلك وإعطاء المستخدم خيارات لحذف بعض‬ ‫●‬
‫الملفات غير الضرورية أو إضافة مساحة إضافية للقرص الصلب‪.‬‬

‫‪Back‬‬ ‫‪Next‬‬
3.7 Protection
● Considering a computer system having multiple users and concurrent execution of multiple processes, the various
processes must be protected from each other's activities.

● Protection refers to a mechanism or a way to control the access of programs, processes, or users to the resources
defined by a computer system.

Following are the major activities of an operating system with respect to protection:
1. The OS ensures that all access to system resources is controlled.
2. The OS ensures that external I/O devices are protected from invalid access attempts.
3. The OS provides authentication features for each user by means of passwords.

‫ حيث يمكن للمدير النظام الحصول على صالحيات كاملة إلجراء أي‬،‫مثال على حماية النظام هو استخدام صالحيات المستخدمين المختلفة‬ ●
.‫ في حين يتم منح المستخدمين العاديين صالحيات محدودة لتنفيذ المهام المطلوبة‬،‫تعديالت على النظام‬

‫ ويتم تخصيص صالحيات لكل مستخدم‬،‫ يتم إنشاء حسابات مستخدمين مختلفة‬،‫ عند تشغيل برنامج على نظام تشغيل ويندوز‬،‫على سبيل المثال‬ ●
‫ كما يتم تحديد الصالحيات‬.‫ لن يتمكن المستخدم من الوصول إلى الملفات أو المجلدات التي ال يملك صالحية الوصول إليها‬،‫ وبالتالي‬.‫حسب الحاجة‬
.‫ مثل الوصول إلى الذاكرة أو الملفات‬،‫الالزمة لتشغيل البرنامج بشكل صحيح‬

Back Next
Operating Systems
Chapter 1: Introduction to Operating Systems
PART 2
Back Next
4. Types of Operating system
■ Batch Operating System
■ Multitasking/Time Sharing OS
■ Multiprocessing OS
■ Real Time OS
■ Distributed OS
■ Network OS
■ Mobile OS

Back Next
‫‪4.1 Batch Operating System‬‬
‫●‬ ‫‪Some computer processes are very lengthy and time-consuming.‬‬

‫●‬ ‫‪To speed the same process, a job with a similar type of needs are batched together and run as a group.‬‬

‫●‬ ‫‪The user of a batch operating system never directly interacts with the computer.‬‬

‫●‬ ‫‪In this type of OS, every user prepares his or her job on an offline device like a punch card and submit it to the computer‬‬
‫‪operator‬‬

‫وتستخدم هذه الطريقة في تشغيل العديد من األنواع المختلفة من التطبيقات مثل معالجة البيانات والمعامالت المصرفية وغيرها‪.‬‬ ‫●‬

‫على سبيل المثال‪ ،‬إذا كان لدينا دفعة تحتوي على ‪ 5‬عمليات مختلفة ()‪ ،processes‬يتم تحميل هذه الدفعة في الذاكرة الرئيسية‪ ،‬ويتم تنفيذها بشكل‬ ‫●‬
‫متتالي ومتكرر حتى االنتهاء من تنفيذ كل العمليات في الدفعة‪ .‬ثم يتم تحميل دفعة جديدة من العمليات وتنفيذها‪ ،‬وهكذا‪.‬‬

‫على سبيل المثال‪ ،‬إذا كان لدينا دفعة تحتوي على ‪ 5‬عمليات مختلفة وتريد تشغيلها في نظام التشغيل دفعة المعالجة‪ ،‬يتم تحميل هذه الدفعة في‬ ‫●‬
‫الذاكرة الرئيسية‪ ،‬ثم يتم تنفيذ العملية األولى حتى االنتهاء منها‪ ،‬ثم يتم تنفيذ العملية الثانية وهكذا حتى االنتهاء من تنفيذ جميع العمليات الموجودة في‬
‫الدفعة‪ ،‬ثم يتم تحميل دفعة جديدة من العمليات وتنفيذها‪.‬‬

‫‪Back‬‬ ‫‪Next‬‬
‫‪4.2 Multi-Tasking/Time-sharing Operating systems‬‬
‫●‬ ‫‪Time-sharing operating system enables people located at a different terminal(shell) to use a single computer‬‬
‫‪system at the same time.‬‬

‫●‬ ‫‪The processor time (CPU) which is shared among multiple users is termed as time sharing.‬‬

‫وتسمح هذه األنظمة بتحميل وتنفيذ العديد من المهام المختلفة بشكل متزامن وفعال‪ ،‬بحيث يمكن للمستخدم استخدام تطبيق وتشغيل برنامج آخر في‬ ‫●‬
‫الخلفية‪.‬‬

‫ويتم ذلك عن طريق تقسيم الوقت والموارد لتخصيص جزء من الوقت لكل تطبيق أو مهمة‪ ،‬ويتم التحكم في تنفيذ هذه المهام عن طريق برامج‬ ‫●‬
‫التحكم وجدولة المهام في النظام‪.‬‬

‫من أمثلة أنظمة التشغيل ‪Multi-Tasking/Time-sharing:‬‬ ‫●‬

‫نظام التشغيل ويندوز‬ ‫●‬

‫‪Back‬‬ ‫‪Next‬‬
4.3 Real time OS
● A real time operating system time interval to process and respond to inputs is very small.
● Examples: Military Software Systems, Space Software Systems

‫ وأنظمة الطائرات وغيرها من التطبيقات التي‬،‫ والتجهيزات الطبية‬،‫ وأجهزة القياس والتحكم‬،‫يستخدم في العديد من التطبيقات مثل التحكم الصناعي‬ ●
.‫تحتاج إلى استجابة فورية‬

Back Next
‫‪4.4 Distributed Operating System‬‬
‫●‬ ‫‪Distributed systems use many processors located in different machines to provide very fast computation to its‬‬
‫‪users.‬‬

‫نظام التشغيل الموزع ‪Distributed Operating System‬هو نظام يتكون من مجموعة من العقد الموزعة ( )‪Distributed Nodes‬التي تعمل معًا‬ ‫●‬
‫كمجموعة واحدة وتتناول المهام بشكل موحد‪ ،‬حتى يبدو للمستخدم وكأنه نظام واحد متكامل‪ .‬يتميز هذا النوع من األنظمة بقابلية التوسع والمرونة‬
‫واألمان العالي‪.‬‬

‫‪Back‬‬ ‫‪Next‬‬
‫‪4.5 Network Operating System‬‬
‫●‬ ‫‪Network Operating System runs on a server.‬‬
‫●‬ ‫‪It provides the capability to serve to manage data, user, groups, security, application, and other networking functions.‬‬

‫يتيح هذا النظام للمستخدمين الوصول إلى الموارد المشتركة مثل الملفات والطابعات والبرمجيات من أي مكان في الشبكة‪ .‬يقوم نظام التشغيل‬ ‫●‬
‫الشبكي بتوزيع الموارد على المستخدمين بشكل فعال ويدير حركة البيانات عبر الشبكة‪.‬‬

‫مثال على نظام التشغيل الشبكي هو نظام تشغيل ‪Windows Server‬الذي يتم استخدامه في الشبكات الكبيرة‪ .‬يوفر ‪Windows Server‬العديد من‬ ‫●‬
‫الميزات المختلفة مثل خدمات الملفات والطباعة وخدمات البريد اإللكتروني واإلدارة المركزية للمستخدمين والمجموعات‪ .‬يتم تنفيذ هذه الميزات‬
‫من خالل الخوادم المتصلة بالشبكة والتي تعمل على تزويد المستخدمين بالموارد المطلوبة بشكل سريع وآمن‪.‬‬

‫‪Back‬‬ ‫‪Next‬‬
4.6 Mobile OS
● Mobile operating systems are those OS which is especially that are designed to power smartphones, tablets, and
wearables devices.

Back Next
The advantage of using Operating System
● Allows you to hide details of hardware by creating an abstraction

● Easy to use with a GUI

● Offers an environment in which a user may execute programs/applications

● The operating system must make sure that the computer system convenient to use

● Operating System acts as an intermediary among applications and the hardware components

● It provides the computer system resources with easy to use format

● Acts as an intermediator between all hardware's and software's of the system

Back Next
Disadvantages of using Operating System
● If any issue occurs in OS, you may lose all the contents which have been stored in your system

● Operating system's software is quite expensive for small size organization which adds burden on them. Example
Windows

● It is never entirely secure as a threat can occur at any time

Back Next
5. Programming languages
● A program, which consists of instructions to the computer, is the means by which we tell computer to perform
certain operations.

● These instructions are logically sequenced and assembled through the action of programming.

● Programmers use a variety of programming languages, such as C and BASIC, to communicate instructions to the
computer.

● System software is one of two categories of the computer software.


● System programs support all applications software by directing the basic functions of the computer.
● Systems software includes programs that help in the development of the applications software.

Back Next
5.1 Generations of Programming Languages
● Programming languages, such as C, Pascal and BASIC, fall within the system software category.

● There are many different programming languages, most of which have highly structured sets of rules. Like computers,
programming languages have evolved in generations.

● With each new generation, fewer instructions are needed to tell the computer to perform a particular task.

● For example, in the fourth-generation language you need only instruct the computer system "what to do", not
necessarily "how to do it". When programming in one of the first three generations of languages, we have to tell the
computer what to do and how to do it. The ease with which the later generations can be used is certainly appealing, but
the earlier languages also have their advantages. All generations of languages are in use today.

Back Next
5.2 The first and second generations
Machine Language
● Each computer has only one programming language that can be executed

● the machine language. We talk of programming in C, Pascal, BASIC, but all these languages must be translated into the
machine language of the computer on which the program is to be executed.

● These and other high-level languages are simply a convenience for the programmer.

Assembler Language
● A set of instructions for an assembler language is essentially one to one with those of a machine language.

● Like machine language, assembler language is unique to a particular computer.

The big difference between the two types is the way the instructions are represented by the programmer.
● Assembler language use easily recognized symbols, called mnemonics to represent instructions.
● For example, mnemonic MUL represents a multiply instruction.
● The assembler languages became the second generation of programming languages.

Back Next
5.3 The third generation
● A third generation programming language belongs in one of two categories: procedure-oriented language and
problem- oriented languages.

Procedure - oriented languages


● A procedure - oriented language permits programmers to model almost any scientific or business procedure.
Instructions are coded, or written, sequentially and processed according to program specifications.

● Procedure - oriented languages are classified as business, scientific, multipurpose and other languages.

Problem - oriented languages


● A problem-objected language is designed to address a particular application area or to solve a particular set of
problem.
● Problem oriented languages do not require the programming detail of procedure-oriented ones.

Back Next
5.4 The fourth generation
● The trend in software development is toward using high-level, user friendly, fourth-generation languages (4GL).

● Fourth-generation languages use high-level English-like instructions to retrieve and format data for inquiries and
reporting.

● Most of the procedure portion of a 4GL program is generated automatically by the computer and the language
software.

● That is, for the most part the programmer specifies what to do, not how to do it.

● The features of a 4GL include limited mathematical manipulation of data, automatic report formatting, sequencing
(sorting), and record selection by criteria.

● SQL, Python, PHP

Back Next
5.5 Natural languages
● Nature language refer to software that enables computer systems to accept, interpret, and execute instructions
in the native, or "natural" language of the end user typically, English.

● The promise for a natural language is that the programmer or user needs little or no training.

● He or she simply writes, or perhaps verbalizes, processing specifications without regard for instruction syntax.

Back Next
6. Compilers and Interpreters
● No matter which high-level language (third and above) a program is written in, it must be translated into machine
language before it can be executed.

● This conversion of high-level instructions into machine-level instructions is done by systems programs called
compilers and interpreters.

Back Next
6.1 Compilers
● The compiler program translates the instructions of a high-level language, such as C, into machine-language
instructions that the computer can interpret and execute.

● A separate compiler or an interpreter is required for each programming language intended for use on a particular
computer system.

● That is, to execute both C and Pascal programs, we must have a C compiler and Pascal compiler.

● High-level programming languages are simply a programmer convenience; they cannot be executed in their source, or
original form.

● The actual high-level programming-language instructions, called the source program, are translated, or
compiled, into machine-language instructions by a compiler.

Back Next
6.2 Interpreters
● An interpreter is a systems program that ultimately performs the same function as a compiler but in a different
manner.

● Instead of translating the entire source program in a single pass,


● an interpreter translates and executes each source program instruction before translating and executing the next.

● The advantage of interpreters over compilers is that an error in instruction syntax is brought to the attention
of the programmer immediately, thereby prompting the programmer to make corrections during program
development.

● The disadvantage of interpreters is that they do not use computing resources as efficiently as a program that
has been compiled. Since the interpreter does not produce an object program, it must perform the translation process
each time a program is executed.

Back Next
Compiler VS Interpreter

compiler interpreter
● translation and compilation happen before ● translation and execution happen together.
execution.
● The interpreter reads each line of code,
● The entire source code is compiled into machine translates it into machine code, and executes it
code, which is then executed. immediately before moving on to the next line.

Back Next
6.3 Loader
● The booting process of Disk-based Operating System begins with load of the so called boot sector, the first
sector of a diskette or hard disk, into system memory.

● One part of the boot sector contains executable codes that are then carried out.

● It results in loading the kernel of the operating system into system memory and transferring the control to the start of
it: the kernel starts running.

● This piece of program, which normally is built in the system ReadOnly-Memory ROM, and loads the first boot sector
is called the system loader or bootstrap loader.

● As illustrated, it instructs the computer to execute another program included in the boot sector, which then loads the
operating system, and starts executing it.

Back Next
6.4 Scheduler
● We have often have situation in which two or more processes are logically runnable.

● When more than one processes are runnable, the operating system must decide which one to run first.

● The part of the operating system concerned with this decision is called the scheduler, and the algorithm it uses is
called the scheduling algorithm.

Back Next
6.4 Scheduler
● The scheduling process can be represented with the help of a queuing diagram.

● Each rectangular box represents a queue, a special buffer structure that can be explained later.
● Two types of queues are present: the ready queue and the device queue.
● The circles represent the resources, which serve the queues, and
● the arrows indicate the flow of processes in the system.

● A process enters the system from the outside world, and is put into the ready queue.
● It waits in the ready queue until it is selected for the CPU.
● After running on the CPU, it waits for an I/O operation by moving to an I/O queue.
● Eventually, it is served by the I/O device and returns to the ready queue.
● A process continues this CPU-I/O cycle until it finishes, and exists from the system.

Long-term Short-term

Ready Queue CPU

I/O Waiting
Back I/O Next
queues
6.4 Scheduler
There are two main schedulers: the long-term scheduler and the short-term scheduler
● The long-term scheduler determines which processes are admitted to the system for processing.

● The short-term scheduler selects among the processes kept in system memory, which are ready to be executed,
and allocates the CPU to one of them.
‫ في حين يمكن استخدام مثال على‬،‫ حيث يقوم بتحديد البرامج التي يجب تنفيذها وحجز مساحة الذاكرة الالزمة لتنفيذها‬،‫مثال على ال ُمخطط الزمني الطويل المدى هو عملية تحميل برنامج‬ ●
.‫ مثل مواعيد تحديدية للرسوميات أو الصوت‬،‫ال ُمخطط الزمني القصير المدى في تطبيقات األلعاب اإللكترونية التي تتطلب مواعيد تحديدية للحصول على أفضلية التنفيذ‬

● In some systems, another additional level of scheduling, the medium-term scheduler, is necessary.
● The key idea behind this kind of scheduler is that it can sometimes be advantageous to remove processes from
memory, and thus reduce the degree of multiprogramming.

Another component involved in the CPU scheduling function is the dispatcher.


● The dispatcher is the module that actually gives control of the CPU to the process selected by the short-term
scheduler.
The functions included are:
1. Loading the registers of the process;
2. Switching to user mode;
3. Jumping to the proper location in the user program to restart it.

Back Next
Thanks!
Do you have any questions?
alisaalah15@gmail.com
01147380654

Credits: This presentation template was created by Slidesgo, and


includes icons by Flaticon, and infographics & images by Freepik

Back Next
Operating Systems

Chapter 2: Introduction to processes and resources


Back Next
1.1 Process definition
● A process is a executing program, including the current values of the program counter, register as well as input
and output values. Conceptually, each process has its own virtual CPU.
● In reality, the real CPU switches back and forth from process to process. To understand the system operations, it is easier to think about a
collection of processes running in (pseudo) parallel than to try to keep track of how the CPU switches from process to process.

● A program by itself is not a process; a program is a passive entity, while a process is an active entity.

● In general, a process will need certain resources such as CPU time, memory, files, I/O devices etc to accomplish
its tasks. These resources are allocated to the process when it is created.

● A single processor may be shared among several processes with some scheduling algorithm being used to
determine when to stop work on one process and service a different one.

● Operating systems that support the process concept must provide some way to create all the processes needed.
● In simple systems, it may be possible to have all the processes that will ever be needed be present when the system comes up.
● In almost all systems however, some way is needed to create and destroy processes as needed during operations.
● In UNIX for instant, processes are created by the fork system call, which makes an identical copy of the calling process.
● In other systems, system calls exist to create a process, load its memory, and start it running.
● In general, processes need a way to create other processes.
● Each process has one parent process, but zero, one, two, or more children processes.

Back Next
1.2 Process states
● As defined, a process is an independent entity with its own input values, output values, and internal state.
● A process often needs to interact with other processes.
● One process may generate some outputs that other process uses as input.

In general, a process can have one of the following five states at a time. 

Back Next
1.2 Process states
S.N. State & Description
1 Start
This is the initial state when a process is first started/created.
2 Ready
The process is waiting to be assigned to a processor. Ready processes are waiting to have the processor allocated to them by
the operating system so that they can run. Process may come into this state after Start state or while running it by but
interrupted by the scheduler to assign CPU to some other process.
3 Running
Once the process has been assigned to a processor by the OS scheduler, the process state is set to running and the processor
executes its instructions.
4 Waiting
Process moves into the waiting state if it needs to wait for a resource, such as waiting for user input, or waiting for a file to
become available.
5 Terminated or Exit
Once the process finishes its execution, or it is terminated by the operating system, it is moved to the terminated state where it
waits to be removed from main memory.

Back Next
‫‪1.2 Process states‬‬
‫لنفترض أن لديك جهاز كمبيوتر وتريد تشغيل برنامج لتحرير النصوص عليه‪ .‬عند النقر على أيقونة البرنامج‪ ،‬يتم تحميل البرنامج من‬ ‫●‬
‫القرص الثابت إلى الذاكرة العشوائية ( )‪RAM‬ويتم إنشاء عملية جديدة في نظام التشغيل لتشغيل البرنامج‪ .‬يمكن أن تمر هذه العملية بعدة‬
‫حاالت مختلفة أثناء تشغيل البرنامج‪ ،‬وهي كما يلي‪:‬‬

‫‪New:‬تم إنشاء العملية وهي في حالة ‪New‬ولم تبدأ بعد‪.‬‬ ‫●‬

‫‪ Ready:‬تم تحميل البرنامج إلى الذاكرة وتم إنشاء العملية‪ ،‬ولكنها تنتظر حتى يتم تخصيص المعالج المركزي لتشغيلها‪ .‬تكون العملية في حالة‬ ‫●‬
‫‪Ready‬في هذه المرحلة‪.‬‬

‫‪ Running:‬يتم تخصيص المعالج المركزي لتشغيل العملية‪ ،‬ويتم تنفيذ البرنامج بالفعل‪ .‬يكون العملية في حالة ‪Running‬في هذه المرحلة‪.‬‬ ‫●‬

‫‪Waiting:‬في بعض األحيان‪ ،‬يتعذر على العملية االستمرار في التنفيذ بسبب عدة أسباب‪ ،‬مثل االنتظار إلدخال بيانات من المستخدم أو انتظار‬ ‫●‬
‫استجابة من أحد األجهزة األخرى‪ .‬يتم تعليق العملية ووضعها في حالة ‪Waiting‬في انتظار حدوث الحدث المطلوب‪.‬‬

‫‪ Terminated:‬بمجرد االنتهاء من تنفيذ البرنامج‪ ،‬تتم إزالة العملية من ذاكرة النظام وتصبح في حالة ‪Terminated.‬‬ ‫●‬

‫بالتالي‪ ،‬بعد تشغيل البرنامج‪ ،‬يمر دورة الحياة الخاصة بالعملية بالتتابع من الحاالت المذكورة أعاله حتى ينتهي تشغيل البرنامج وتتم إزالة‬ ‫●‬
‫العملية من ذاكرة النظام‪.‬‬

‫‪Back‬‬ ‫‪Next‬‬
1.3 Implementation of processes
● To implement the process model, the operating system maintains a table, an array of structures, called the
process table.

● Each entry identifies a process with information such as process state, its program counter, stack pointer, memory
allocation, the status of its open files, its accounting and scheduling information.

● In another words, it must contain everything about the process that must be saved when the process is switched from the running state to the
ready state so that it can be restarted later as if it had never been stopped.
● The switching between two processes is illustrated by Figure

Back Next
1.3 Implementation of processes
● Each process is identified with its own process control block, PCB, which is a data block containing all information
associated with this process.

● A Process Control Block is a data structure maintained by the Operating System for every process.
● The PCB is identified by an integer process ID (PID).
● A PCB keeps all the information needed to keep track of a process as listed below in the table:  

‫ ويحتوي على معلومات عن العملية مثل اسم الملف الذي‬،‫ لكل عملية للطباعة‬PCB ‫حيث يتم إنشاء‬Windows. ‫هو عملية الطباعة في نظام التشغيل‬PCB ‫مثال على‬ ●
‫ تستخدم‬.‫ وغيرها من المعلومات الالزمة لتشغيل العملية بنجاح‬،)‫ والحالة الحالية للعملية (مثل الطباعة أو االنتظار‬،‫ وعدد الصفحات المتبقية للطباعة‬،‫سيتم طباعته‬
.‫هذه المعلومات من قبل نظام التشغيل للتحكم في تنفيذ العملية والتأكد من تحقيق األهداف المطلوبة‬

Back Next
1.3 Implementation of processes
S.N. Information & Description
1 Process State
The current state of the process i.e., whether it is ready, running, waiting, or whatever.

2 Process privileges
This is required to allow/disallow access to system resources.
3 Process ID
Unique identification for each of the process in the operating system.
4 Pointer
A pointer to parent process.
5 Program Counter
Program Counter is a pointer to the address of the next instruction to be executed for this process.

6 CPU registers
Various CPU registers where process need to be stored for execution for running state.
7 CPU Scheduling Information
Process priority and other scheduling information which is required to schedule the process.
8 Memory management information
This includes the information of page table, memory limits, Segment table depending on memory used by the operating system.
9 Accounting information
This includes the amount of CPU used for process execution, time limits, execution ID etc.
10 IO status information
This includes a list of I/O devices allocated to the process.
1.3 Implementation of processes
● The architecture of a PCB is completely dependent on Operating System and may contain different information in different operating systems.
● Here is a simplified diagram of a PCB. A PCB structure is shown in Figure 6.

Pointer State
Process number
Program counter

Registers

Memory limits
List of open files

Back Next
1.3 Implementation of processes
● A process may create several new processes during its time of execution.
● The creating process is called parent process, while the new processes are called children processes.

There are different possibilities concerning creating new processes:


○ Execution: the parent process continues to execute concurrently with its children processes or
it waits until all of its children processes have terminated (sequential).

○ Sharing: either the parent and children processes share all resources (likes memory or files) or
the children processes share only a subset of their parent's resources or
the parent and children processes share no resources in common.

A parent process can terminate the execution of one of its children for one of theses reasons:
● The child process has exceeded its usage of the resources it has been allocated. In order to do this, a mechanism
must be available to allow the parent process to inspect the state of its children processes.
● The task assigned to the child process is no longer required.

Back Next
1.3 Implementation of processes
We distinguish between independent process and cooperating process.

● A process is independent if it cannot affect or be affected by other processes executing in the system.

this type of processes has following features:


● Its state is not shared in any way by any other process.
● Its execution is deterministic, i.e. the results of execution depend only on the input values.
● Its execution is reproducible, i.e., the results of execution will always be the same for the same input.
● Its execution can be stopped and restarted without any negative effect.
،‫ فعند تشغيل المشغل يتم إنشاء عملية مستقلة تعمل على قراءة الملفات الصوتية وتشغيلها‬،‫مثال على عملية مستقلة في نظام التشغيل هو برنامج تشغيل مشغل الصوت على الحاسوب‬ ●
.‫ يمكن إغالق المشغل دون التأثير على أي عملية أخرى في النظام‬،‫ وبالتالي‬.‫وال يوجد أي تدخل من أي عملية أخرى في النظام خالل عملية التشغيل‬

● cooperating processes can affect or be affected by other processes executing in the system.
They are characterized by:
● Their states are shared by other processes;
● Its execution is not deterministic, i.e., the results of execution depend on relative execution sequence and can not
be predicted in advance;
● Its execution is irreproducible, i.e., the results of execution are not always the same for the same input.
‫ يتم تخزين هذا النص في‬،‫ فعندما يقوم المستخدم بكتابة نص في برنامج التحرير‬.‫مثال على العمليات التي تتعاون في نظام التشغيل هو برنامج تحرير النصوص وبرنامج الطباعة على الحاسوب‬ ●
‫ ويتم تبادل البيانات بين البرامج باستخدام ميزانيات النظام المخصصة للتواصل بين‬.‫ ثم يتعاون برنامج الطباعة مع برنامج التحرير عندما يقوم المستخدم بطلب طباعة النص‬،‫الذاكرة المؤقتة‬
‫ وبهذه الطريقة يتعاون البرنامجان مع بعضهما البعض لتنفيذ وظيفة محددة‬.‫ حيث يتم تحميل النص الذي تم كتابته من برنامج التحرير إلى برنامج الطباعة ليتم طباعته على الورق‬،‫العمليات‬
2. Interprocess communication
● Principally, there exist two complementary interprocess communication types:
● a) shared-memory system and b) message passing system.
● It is clear that these two schemes are not mutually exclusive, and could be used simultaneously within a single
operating system.

2.1 Shared-memory system


● Shared-memory systems require communication processes to share some variables.
● The processes are expected to exchange information through the use of these shared variables.
● the responsibility for providing communication rests with the application programmers.
● The operating system only needs to provide shared memory.

2.2 Message-passing system


● Message passing systems allow communication processes to exchange messages.
● In this scheme, the responsibility rests with the operating system itself.
● The function of a message-passing system is to allow processes to communicate with each other without the need to
resort to shared variable.

Back Next
2. Interprocess communication
● An interprocess communication facility basically provides two operation: send (message) and receive
(message).
● In order to send and to receive messages, a communication link must exist between two involved processes.
● This link can be implemented in different ways.

● The possible basic implementation questions are:


● How are links established?
● Can a link be associated with more than two processes?
● How many links can there be between every pair of process? - What is the capacity of a link? That is, does the link
have some buffer space? If so, how much?
● What is the size of the message? Can the link accommodate variable size or fixed-size message? - Is the link
unidirectional or bi-directional?

Back Next
2.3 Exception Conditions
● In a distributed computing environment, where communication between different processes is needed, the
probability that an error will occur is relative higher than in an single-machine environment.

● If message-passing systems are implemented in shared memory in a single-machine, the entire system fails if failure
occurs.

● However, in a distributed environment, message-passing systems are usually handled by communication lines, and
the failure of one site doesn't necessary result in the failure of the entire system.

● Normally, failure events are called exception conditions and this case, some error recovery mechanism, i.e.,
exception condition handling, must take place.

‫التي تؤدي إلى إيقاف‬Exception Conditions ‫ فسيتم توليد حالة االستثناء‬،‫ إذا كان البرنامج يحاول قسمة عدد على الصفر‬،‫على سبيل المثال‬ ●
‫ مثل‬،‫ يمكن للنظام التعامل مع هذه الحالة بأحد الطرق المناسبة‬،‫ وبعد ذلك‬.‫تنفيذ البرنامج وإظهار رسالة خطأ تفيد بأنه تم قسمة عدد على الصفر‬
.‫إغالق البرنامج أو إعادة تشغيله بعد إجراء التعديالت الالزمة‬

Back Next
3. Process scheduling
● Principally, process scheduling means CPU scheduling, the basic function of a multiprogramming system.
● By switching the CPU between different processes, the operating system helps to increase the CPU utilization.

● The idea of multiprogramming is quite simple. Several processes are kept in memory at time. When one process has
to wait, the operating system takes the CPU from that process, and gives it to another process.

Back Next
Schedulers
● Schedulers are special system software which handle process scheduling in various ways.
● Their main task is to select the jobs to be submitted into the system and to decide which process to run.
● Schedulers are of three types: Long-Term Scheduler Short-Term Scheduler Medium-Term Scheduler

Long Term Scheduler


● It is also called a job scheduler. A long-term scheduler determines which programs are admitted to the system for
processing.
● It selects processes from the queue and loads them into memory for execution.

● Process loads into the memory for CPU scheduling.

● The primary objective of the job scheduler is to provide a balanced mix of jobs, such as I/O bound and processor
bound.
● It also controls the degree of multiprogramming

● Time-sharing operating systems have no long term scheduler.

● When a process changes the state from new to ready, then there is use of long-term scheduler.
Back Next
Schedulers
● Schedulers are special system software which handle process scheduling in various ways.
● Their main task is to select the jobs to be submitted into the system and to decide which process to run.
● Schedulers are of three types: Long-Term Scheduler Short-Term Scheduler Medium-Term Scheduler

Short Term Scheduler


● It is also called as CPU scheduler. Its main objective is to increase system performance in accordance with the chosen
set of criteria.

● It is the change of ready state to running state of the process.

● CPU scheduler selects a process among the processes that are ready to execute and allocates CPU to one of them.

● Short-term schedulers, also known as dispatchers, make the decision of which process to execute next.

● Short-term schedulers are faster than long-term schedulers.

Back Next
Schedulers
● Schedulers are special system software which handle process scheduling in various ways.
● Their main task is to select the jobs to be submitted into the system and to decide which process to run.
● Schedulers are of three types: Long-Term Scheduler Short-Term Scheduler Medium-Term Scheduler

Medium Term Scheduler


● Medium-term scheduling is a part of swapping. It removes the processes from the memory.
● It reduces the degree of multiprogramming.

● The medium-term scheduler is in-charge of handling the swapped out-processes.

● A running process may become suspended if it makes an I/O request.

● A suspended processes cannot make any progress towards completion.

● In this condition, to remove the process from memory and make space for other processes, the suspended process is
moved to the secondary storage.

● This process is called swapping, and the process is said to be swapped out or rolled out.

Back Next
Comparison among Scheduler
S.N Long-Term Short-Term Medium-Term
. Scheduler Scheduler Scheduler
1 It is a job scheduler It is a CPU scheduler It is a process swapping scheduler.

2 Speed is lesser than short term Speed is fastest among other two Speed is in between both short
scheduler and long term scheduler.

3 It controls the degree of It provides lesser control over It reduces the degree of
multiprogramming degree of multiprogramming multiprogramming.
4 It is almost absent or minimal in It is also minimal in time sharing It is a part of Time sharing
time sharing system systems.
system
5 It selects processes from pool and It selects those processes which It can re-introduce the process
loads them into memory for are ready to execute into memory and execution can be
execution continued.

Back Next
4. Resources and Deadlocks
● In a computer system, we have a finite number of resources to be distributed among a number of competing
processes.

● These system resources are classified in several types, such as CPU cycle, memory space, files and I/O devices
(printers, tape drives, terminal etc.).

● Each resource type can have some number of identical instances. For example: if a system has two CPUs, then the
resource type CPU has two identical instances.

● A process must request a resource before using it and release the resource after using it. It is clear that the number of
resource requested can not be exceed the total number of resources available in the system.

Under normal operation, a process may utilize a resource only in the following sequence:
● Request: if the request can not be immediately granted, then the requesting process must wait until it can get the
resource.
● Use: the requesting process can operate on the resource.
● Release: the process releases the resource after using it.

Back Next
4. Resources and Deadlocks
● A set of processes is in a deadlock state when every process in the set is waiting for an event that can only be caused
by another process in the set. Consider a system with three disk drives

● Suppose there are three processes, each is holding one of these three disk drives.

● If each process now requests another disk drive, three processes will be in a deadlock state, because each process is
waiting for the event "disk drive is released", which can only be caused by one of the other waiting process.

● Deadlock state will occur involving processes competing not only for the same resource type, but also for different
resource types. Figure 1 shows possibility and occurrence of deadlock

R1 ‫إلى‬A ‫تحتاج‬R2. ‫و‬R1 ‫وموردان‬B ‫و‬A ‫مثال على االنسداد يحدث عندما تتوفر عمليتان‬
‫تم حجزه‬R2 ‫إلكمال عملها ولكن‬R2 ‫الحصول على‬A ‫تحاول‬R2. ‫تحتاج إلى‬B ‫إلكمال عملها و‬
‫تم حجزه‬R1 ‫إلكمال عملها ولكن‬R1 ‫الحصول على‬B ‫ تحاول‬،‫في نفس الوقت‬B. ‫بالفعل بواسطة‬
‫ ويصبح من المستحيل إنهاء أي‬،‫يتم تعطيل العمليتين ويتم حجز الموارد بشكل دائم‬A. ‫بالفعل بواسطة‬
.‫من العمليتين بدون إطالق الموارد‬

Back Next
4. Resources and Deadlocks
● There is no single effective strategy that can deal with all types of deadlock. Three approaches are common:

● ٠ Deadlock prevention: Disallow one of the three necessary conditions for deadlock occurrence, or prevent circular
wait condition from happening.

● ٠ Deadlock avoidance: Do not grant a resource request if this allocation might lead to deadlock.

● ٠ Deadlock detection: Grant resource requests when possible, but periodically check for the presence of deadlock
and take action to recover

Back Next
4. Resources and Deadlocks
● An approach to solving the deadlock problem that differs subtly from deadlock prevention is deadlock avoidance.

● In deadlock prevention, we constrain resource requests to prevent at least one of the four conditions of deadlock.
This is either done indirectly by preventing one of the three necessary policy conditions (mutual exclusion, hold and
wait, no preemption), or directly by preventing circular wait. This leads to inefficient use of resources and inefficient
execution of processes.

● Deadlock avoidance, on the other hand, allows the three necessary conditions but makes judicious choices to assure
that the deadlock point is never reached. As such, avoidance allows more concurrency than prevention. With deadlock
avoidance, a decision is made dynamically whether the current resource allocation request will, if granted, potentially
lead to a deadlock. Deadlock avoidance thus requires knowledge of future process resource requests.

● There are two approaches to deadlock avoidance:


● 1. Do not start a process if its demands might lead to deadlock.
● 2. Do not grant an incremental resource request to a process if this allocation might lead to deadlock.

Back Next
Operating Systems
Chapter 2: Introduction to processes and resources
Part 2
1. FCFS
2. SJF (Non-preemptive)
3. RR
Back Next
3. Process scheduling
● Principally, process scheduling means CPU scheduling, the basic function of a multiprogramming system.
● By switching the CPU between different processes, the operating system helps to increase the CPU utilization.

● The idea of multiprogramming is quite simple. Several processes are kept in memory at time. When one process has
to wait, the operating system takes the CPU from that process, and gives it to another process.

Back Next
A. First-Come-First-Served
● (FCFS) algorithm, i.e., the process which requests the CPU first is allocated the CPU first.
● The FCFS algorithm is simply realized with a FIFO queue.

● First Come First Serve (FCFS)


● Jobs are executed on first come, first serve basis.
● It is a non-preemptive, pre-emptive scheduling algorithm.
● Easy to understand and implement.
● Its implementation is based on FIFO queue.
● Poor in performance as average wait time is high.
:‫لنفترض أن لدينا ثالث مهام‬ ●

.‫ وحدات زمنية إلنجازها‬5 ‫تحتاج إلى‬A ‫● مهمة‬


.‫ وحدات زمنية إلنجازها‬2 ‫تحتاج إلى‬B ‫● مهمة‬
.‫ وحدات زمنية إلنجازها‬4 ‫تحتاج إلى‬C ‫● مهمة‬
:‫ فسيتم ترتيبها كالتالي‬،‫على هذه المهام‬FCFS ‫إذا تم تنفيذ الخوارزمية‬
.‫ وحدات زمنية‬5 ‫لمدة‬A ‫● تنفيذ المهمة‬
.‫ وحدات زمنية‬2 ‫لمدة‬B ‫● تنفيذ المهمة‬
.‫ وحدات زمنية‬4 ‫لمدة‬C ‫● تنفيذ المهمة‬

Back Next
A. First-Come-First-Served
● First Come First Serve (FCFS)

Process Wait Time :


Service Time - Arrival Time
P0 0-0=0
P1 5-1=4
P2 8-2=6
P3 16 - 3 = 13
Average Wait Time: (0+4+6+13) / 4 = 5.75

Back Next
A. First-Come-First-Served
● First Come First Serve (FCFS)
Process Processing Time

P1 24
P2 3
P3 3

Process Wait Time :


P1 0
P2 24
P3 27
Average Wait Time: (51) / 3 = 17

Back Next
B. Priority algorithm
● Priority can be associated with each process depending on how urgently a process should execute.

● The CPU is then allocated to the process with the highest priority.

● Equal priority processes are scheduled by the FCFS algorithm.

Priorities can be defined either internally or externally.


● Internally defined priorities use some measurable quantity or quantities to compute the priority of a process,
● for example: time limits, memory requirements, the number of open files etc.

● External priorities are set by criteria that are external to the operating system,
● such as the type and the amount of funds being paid for computer use and other external, often political factors.
:‫مثال على نظام األولوية‬ ●
:‫ عمليات‬3 ‫لدينا‬ ●
.‫ وحدات من الوقت إلكمالها‬5 ‫ وتحتاج إلى‬1 ‫مع أولوية‬A ‫عملية‬ ●
.‫ وحدات من الوقت إلكمالها‬3 ‫ وتحتاج إلى‬2 ‫مع أولوية‬B ‫عملية‬ ●
.‫ وحدات من الوقت إلكمالها‬2 ‫ وتحتاج إلى‬3 ‫مع أولوية‬C ‫عملية‬ ●
‫ ثم تأتي‬،‫ لذا تنفذ أوال‬،‫ إال أنها تتمتع بأعلى أولوية‬،‫تحتاج إلى وقت أطول إلنهائها‬A ‫ وعلى الرغم من أن عملية‬،‫ يتم تحديد ترتيب تنفيذ العمليات‬،‫بنا ًء على أولوية العمليات‬ ●
.‫في النهاية‬C ‫ ثم عملية‬،‫ثانيا‬B ‫عملية‬

Back Next
B. Priority algorithm
● One of the critical problems with priority scheduling algorithms is the indefinite blocking or starvation.

A process that is ready to run but lacking the CPU can be considered blocked, waiting for the CPU.

● A priority scheduling algorithm can leave some low-priority processes waiting indefinite for the CPU.

● In a heavy loaded computer system, a steady stream of high-priority processes can prevent a low-priority
process from ever getting the CPU.

● Another solution to the problem of indefinite blockage of low-priority processes is aging.

● Aging is the technique of gradually increasing the priority of the processes that wait in the system for a long
time.

● For example, if 0 is the lowest and 127 is the highest priority, we could increment a waiting process's priority by 1 every
15 minutes. Even a process with an initial priority of 0 would have the highest priority in the system and would execute.

Back Next
C. Preemptive algorithm
● All the priority algorithms mentioned above are non-preemptive scheduling algorithms, i.e., once the CPU has been
allocated to a process, it can keep the CPU until it releases it, either by terminating or by requesting I/O devices.
● Non-preemptive scheduling algorithms will simply put the new process at the head of the ready queue.
‫ وتم إعطاء أولوية‬،‫ وحدات زمنية‬5 ‫تحتاج لـ‬B ‫ وحدات زمنية إلكمالها و‬10 ‫لـ‬A ‫ حيث تحتاج‬،B ‫و‬A ‫ إذا كان لدينا مهمتين‬،‫● على سبيل المثال‬
‫ بغض النظر عن أي مهمة‬،B ‫أوالً وبعد االنتهاء منها يتم تنفيذ المهمة‬A ‫ في خوارزمية غير القابلة لالنقطاع سيتم تنفيذ المهمة‬،A ‫أعلى للمهمة‬
.‫جديدة قد تصل خالل هذا الوقت‬

● A preemptive priority scheduling algorithm will preempt the CPU if the priority of the newly arrived process
is higher than the priority of the currently running process.

● When a process arrives at the ready queue, its priority is compared with the priority of the currently running
process.

● Due to the preemptive scheduling algorithm, the new process will execute only if its priority is higher than the
priority of the running process

‫ فإن‬،‫ذات األولوية األعلى‬B ‫ وجاءت عملية‬،‫في حالة تنفيذ‬A ‫ وكانت عملية‬،‫في الطابور‬B ‫و‬A ‫ إذا كان هناك عمليتان‬،‫على سبيل المثال‬ ●
.‫تنفيذها من حيث توقفت‬A ‫ تستأنف عملية‬،B ‫ وبعد االنتهاء من عملية‬.‫بالتنفيذ‬B ‫وتسمح لعملية‬A ‫خوارزمية اإلجبارية تتدخل وتوقف عملية‬

Back Next
C. Preemptive algorithm
● Round-robin scheduling is preemptive algorithm.

● Each process is assigned a time interval, called its quantum, which it is allowed to run.

● If the process is still running at the end of the quantum, the CPU is preempted, and given to another process.
● If the process has blocked or finished before the quantum has elapsed, the CPU switching is done.

‫ حيث تُخصص فترة زمنية محددة لكل مهمة تسمى الكم‬،‫تعتمد الخوارزمية على تقسيم الوقت بين المهام المختلفة بطريقة متساوية‬ ●
.‫ ويتم تحديد حجم هذا الكم الزمني من قبل المستخدم‬،time quantum)(‫الزمني‬

‫ في حال انتهت المهمة‬.‫ ثم تُعيد الخوارزمية إلى المهمة التالية في القائمة‬،‫ يتم تخصيص الوقت الالزم لها من قِ َبل الخوارزمية‬،‫عندما تبدأ المهمة‬ ●
.‫ يتم تبديل المهمة الجديدة ويُعيد العملية مرة أخرى‬،‫قبل نهاية الفترة المحددة‬

Back Next
C. Preemptive algorithm
● Shortest Job First (SJF)

● This is also known as shortest job next, or SJN


● This is a non-preemptive, pre-emptive scheduling algorithm.
● Best approach to minimize waiting time.
● Easy to implement in Batch systems where required CPU time is known in advance.
● Impossible to implement in interactive systems where required CPU time is not known.
● The processer should know in advance how much time process will take.

:‫ وتنقسم الخوارزمية إلى نوعين‬.ً‫على اختيار العملية األقصر من حيث مدة التنفيذ لتنفيذها أوال‬Shortest Job First (SJF)" " ‫تعتمد خوارزمية‬ ●

‫ حيث يمكن لعملية ذات أولوية عالية أن تقوم بأخذ الوحدة المعالجة المركزية من عملية ذات أولوية منخفضة إذا كانت‬،Pre-emptive SJF"" -1 ●
.‫مدة تنفيذها أقصر من المدة المتبقية لعملية األولوية العالية‬

.‫ حيث يتم اختيار العملية التي يتوقع أن تنتهي في أقصر وقت لتنفيذها بشكل كامل‬،Non-Preemptive SJF"" -2 ●

Back Next
● Shortest-Job-First (SJF) Scheduling (non-preemptive)
Process Arrival Time Processing
Time
P1 0 7
P2 2 4
P3 4 1
P4 5 4

Process Wait Time :


Service Time - Arrival Time
P1 0
P2 8-2 = 6
P3 7-4 = 3
P4 12-5 = 7
Average Wait Time: (0+6+3+7) / 4 = 4
Back Next
C. Preemptive algorithm
● Round Robin Scheduling

● Round Robin is the preemptive process scheduling algorithm.


● Each process is provided a fix time to execute, it is called a quantum.
● Once a process is executed for a given time period, it is preempted and other process executes for a given time period.
● Context switching is used to save states of preempted processes.

Back Next
C. Preemptive algorithm
● Round Robin Scheduling
Process Arrival Time Execution Time
Process Wait Time :
P0 0 5 2 0 Service Time - Arrival Time
P1 1 3 0 P0 (0 - 0) + (12 - 3) = 9
P2 2 8 5 2 0 P1 (3 - 1) = 2
P3 3 6 3 0 P2 (6 - 2) + (14 - 9) + (20 - 17) = 12
P3 (9 - 3) + (17 - 12) = 11
Average Wait Time: (9+2+12+11) / 4 = 8.5

Back Next
C. Preemptive algorithm
● Round Robin (RR) With Quantum= 20

Process Processing Time


P1 53
P2 17
P3 68
P4 24

Back Next
Exercise 1
Process Arrival Time Execution Time

A 0 3
B 1 5
C 3 2
D 9 5
● 1. FCFS
E 12 5
● 2. SJF (Non-preemptive)
● 3. RR with Quantum= 2

Back Next
Exercise 1 1. FCFS
Process Arrival Time Execution Time

A 0 3
B 1 5 A B C D E

C 3 2 0 3 8 10 15 20

D 9 5
Process Wait Time :
E 12 5
Service Time - Arrival Time
A 0-0=0
B 3-1=2
C 8-3=5
D 10 - 9 = 1
E 15-12 = 3
Average Wait Time: (0+2+5+1+3) / 5 = 2.2
Back Next
Exercise 1 2. SJF (Non-preemptive)
Process Arrival Time Execution Time

A 0 3
B 1 5 A C B D E

C 3 2 0 3 5 10 15 20

D 9 5
Process Wait Time :
E 12 5
Service Time - Arrival Time
A 0-0=0
B 5-1=4
C 3-3=0
D 10 - 9 = 1
E 15-12 = 3
Average Wait Time: (0 + 0 + 4 + 1 + 3) / 5 = 1.6
Back Next
Exercise 1 RR with Quantum= 2
A B C D E A B D E B D E
0 2 4 6 8 10 11 13 15 17 18 19 20

Process Wait Time :


Service Time - Arrival Time
Process Arrival Time Execution Time
A (0 – 0) + (10-2) = 8
A 0 3 1 0
B (2-1) + (11-4) + (17-13)= 12
B 1 5 3 1 0
C (4-3) = 1
C 3 2 0
D (6-9) + (13-8) + (18-15) = 5
D 9 5 3 1 0
E (8-12) + (15-10) + (19-17) = 3
E 12 5 3 1 0
Average Wait Time: (29) / 5 = 5.8
Back Next
Exercise 2:

● 1. FCFS (0 + 0 + 8 + 8) / 4 = 4.0
● 2. SJF (Non-preemptive) (0 + 1 + 2 + 9) / 4 = 3.0
● 3. RR with Quantum= 2 (1 + 7 + 1 + 12) / 4 = 5.25

Back Next

You might also like