Mol 5 Sat
Mol 5 Sat
Hardware Elements
Processor
Main Memory
volatile
I/O modules
secondary memory devices
communications equipment
terminals
System bus
communication among processors, memory, and I/O modules
Storage Structure
Main memory – only large storage media that the CPU can access
directly.
Secondary storage – extension of main memory that provides large
nonvolatile storage capacity.
Magnetic disks –
Disk surface is logically divided into tracks, which are subdivided into sectors.
Storage Hierarchy
Storage systems organized in hierarchy.
Speed
Cost
Volatility
Decreasing cost per bit
Increasing capacity
Increasing access time
Decreasing frequency of access of the memory by the processor
Caching – copying information from slower into faster storage system;
main memory can be viewed as a last cache for secondary storage.
Faster storage (cache) checked first if information is there
If it is, information used directly from the cache (fast)
If not, data copied to cache and used there
Cache smaller than storage being cached
A portion of main memory used as a buffer to hold data for the disk
Some data written out may be referenced again. The data are retrieved rapidly from
the software cache instead of slowly from disk
I/O Operation
After I/O starts, control returns to user program only upon I/O completion
Wait instruction idles the CPU until the next interrupt
At most one I/O request is outstanding at a time, no simultaneous I/O processing.
Direct Memory Access (DMA) Structure
I/O exchanges occur directly with memory
Processor grants I/O module authority to read from or write to memory
Processor is free to do other things
Device controller transfers blocks of data from buffer storage directly
to main memory without CPU intervention.
Only one interrupt is generated per block, rather than the one interrupt
per byte.
Computer-System Operation
I/O devices and the CPU can execute concurrently.
Each device controller is in charge of a particular device type.
Each device controller has a local buffer.
CPU moves data from/to main memory to/from local buffers
I/O is from the device to local buffer of controller.
Device controller informs CPU that it has finished its operation by
causing an interrupt.
Instruction Cycle
The processor fetches the instruction from memory
Program counter (PC) holds address of the instruction to be fetched next
Program counter is incremented after each fetch
Fetched instruction is placed in the instruction register
Types of instructions
transfer data between processor and memory
data transferred to or from a peripheral device
arithmetic or logic operation on data
Interrupts
Most I/O devices are slower than the processor (writing to a line
printer)
Processor must pause to wait for device
Interrupts allow the processor to execute other instructions while an
I/O operation is in progress
Process being interrupted must be suspended in such a way so that it
can be resumed once the operation is complete
Improves processing efficiency
Interrupt Handling
Interrupt transfers control to the interrupt service routine generally,
through the interrupt vector, which contains the addresses of all the
service routines.
Interrupt architecture must save the address of the interrupted
instruction.
The operating system preserves the state of the CPU by storing
registers and the program counter
Types of Interrupt
Software interrupt
arithmetic overflow
division by zero
execute illegal instruction
reference outside user’s memory space
Hardware interrupt
When a hardware device needs the processor's attention, it simply sends an
electrical signal (hardware interrupt).
I/O operation
After I/O starts, control returns to user program without waiting for I/O completion.
System call – request to the operating system to allow user to wait for I/O
completion.
Device-status table contains entry for each I/O device indicating its type, address,
and state.
Operating system indexes into I/O device table to determine device status and to
modify table entry to include interrupt
Operating-System Operations
Dual-mode operation allows OS to protect itself and other system
components
User mode and kernel mode
Mode bit provided by hardware
Providesability to distinguish when system is running user code or kernel code
Some instructions designated as privileged, only executable in kernel mode
System call changes mode to kernel, return from call resets it to user
Parallel systems
SMP = Symmetric MultiProcessing
All CPUs are peers and concurrently run the same copy of O/Sin memory
a Symmetric or "Master - Slave" MultiProcessing
one CPU runs the O/S. Others ask for tasks to do
Real-time systems
systems controlling scientific experiments, medical imaging systems, industrial control
systems, some display systems
“Hard” real-time: critical tasks are guaranteed on time
secondary storage limited or absent, data stored in short term memory, or read-only memory
(ROM)
conflicts with time-sharing systems and virtual memory delays
“Soft” real-time: critical tasks just get higher priority
more useful in applications requiring tight but not strict response times ( multimedia, virtual
reality, robotic exploration)
OS - Main Components
Process management
process creation; deletion; suspension
process synchronization; communication
Main-memory management
Manage used parts and their current users
Select processes to load
Allocate memory to running processes
Secondary storage management
Free-space management
Storage allocation
File system management
File + directory creation; deletion
File manipulation primitives
Mapping files onto secondary storage
I/o system management
general device-driver interface
Drivers for specific hardware devices
Protection system
Distinguish between authorized and unauthorized usage
Provide means of enforcement
Command-interpreter System
Controlstatements that deal with process creation and
management + I/o handling + file-system access + protection +
networking
Introduction
A. Users: The user’s view of the computer varies according to the interface being used.
a. Single user
i. Want convenience, ease of use
ii. Don’t care about resource utilization
iii. Such systems are optimized for the single-user experience rather than the requirements of multiple
users.
b. Multiple users
i. User sits at a terminal connected to a mainframe or a minicomputer. Other users are accessing the
same computer through other terminals. These users share resources and may exchange
information. The operating system in such cases is designed to maximize resource utilization.
ii. Users of dedicate systems such as workstations have dedicated resources but frequently use shared
resources from servers Therefore, their operating system is designed to compromise between
individual usability and resource utilization.
iii. Handheld computers are resource poor, optimized for usability and battery life
iv. Some computers have little or no user interface, such as embedded computers in devices and
automobiles
B. System:
a. OS is a resource allocator
i. Manages all resources (CPU time, memory space, file-storage space, I/O devices, … …)
ii. Decides between conflicting requests for efficient and fair resource use
b. OS is a control program
Page 1 of 10
i. Controls execution of programs to prevent errors and improper use of the computer
A Narrow Definition: “The one program running at all times on the computer” is the kernel.
Everything else is either a system program (ships with the operating system) or an application program.
Computer Startup:
For a computer to start running—for instance, when it is powered up or rebooted—it needs to have an initial
program to run.
This initial program, or [bootstrap program] tends to be simple
Typically, it is stored within the computer hardware in read-only memory (ROM) or electrically erasable programmable
read-only memory (EEPROM), known by the general term firmware.
It initializes all aspects of the system, from CPU registers to device controllers to memory contents.
The bootstrap program must know how to load the operating system and how to start executing that system.
To accomplish this goal, the bootstrap program must locate the operating-system kernel and load it into memory.
Once the kernel is loaded and executing, it can start providing services to the system and its users.
12. The operating system preserves the state of the CPU by storing registers and the program counter
13. Determines which type of interrupt has occurred:
a. polling
b. vectored interrupt system
14. Separate segments of code determine what action should be taken for each type of interrupts.
Page 2 of 10
Storage Structure
A. Main memory:
a. Only storage media that the CPU can access directly
b. So any programs to run must be stored there.
c. Its advantage random access
d. Its disadvantage typically volatile (loses all data when computer shuts down).
B. Secondary storage:
a. Extension of main memory that provides large nonvolatile storage capacity
b. Examples
i. Magnetic disks
1. rigid metal or glass platters covered with magnetic recording material
2. Disk surface is logically divided into tracks, which are subdivided into sectors
3. The disk controller determines the logical interaction between the device and the
computer
ii. Solid-state disks (faster than magnetic disks)
1. Various technologies
2. Becoming more popular
1. Speed
2. Cost
3. Volatility
Caching:
Page 3 of 10
5. Faster storage (cache) checked first to determine if information is there
a. If it is, information used directly from the cache (fast)
b. If not, data copied to cache and used there
6. Cache smaller than storage being cached (Cashe has smaller size than data wanted to be stored)
a. Cache management important design problem
b. Cache size and replacement policy
Device Driver:
I/O Structure:
N.B:
1. This form of interrupt-driven I/O is fine for moving small amounts of data but can produce high overhead
when used for bulk data movement such as disk I/O.
2. To solve this problem, direct memory access (DMA) is used.
B. Second Method (Asynchronous)
1. After setting up buffers, pointers, and counters for the I/O device, the device controller transfers an
entire block of data directly to or from its own buffer storage to memory, with no intervention by the
CPU.
2. Only one interrupt is generated per block, to tell the device driver that the operation has completed,
rather than the one interrupt per byte generated for low-speed devices.
3. While the device controller is performing these operations, the CPU is available to accomplish other
work.
Multiprocessing can cause a system to change its memory access model from uniform memory access (UMA) to
non-uniform memory access (NUMA).
o UMA: is defined as the situation in which access to any RAM from any CPU takes the same amount of time.
o NUMA: some parts of memory may take longer to access than other parts, creating a performance penalty.
Operating systems can minimize the NUMA penalty through resource management.
A recent trend in CPU design is to include multiple computing cores on a single chip. Such multiprocessor systems are
termed multicore.
They can be more efficient than multiple chips with single cores because on-chip communication is faster than
between-chip communication.
In addition, one chip with multiple cores uses significantly less power than multiple single-core chips.
It is important to note that while multicore systems are multiprocessor systems, not all multiprocessor systems
are multicore,
Blade Servers are a relatively recent development in which multiple processor boards, I/O boards, and networking
boards are placed in the same chassis.
The difference between these and traditional multiprocessor systems is that each blade-processor board boots
independently and runs its own operating system.
Some blade-server boards are multiprocessor as well, which blurs the lines between types of computers.
Clustered System
Like multiprocessor systems, but multiple systems working together
o Usually sharing storage via a storage-area network (SAN)
o Provides a high-availability service which survives failures even if one or more systems in the cluster fail.
Asymmetric clustering: The hot-standby host machine does nothing but monitor the active
server. If that server fails, the hot-standby host becomes the active server.
Symmetric clustering has multiple nodes running applications, monitoring each other
Page 5 of 10
1.4 Operating-System Structure
One of the most important aspects of operating systems is the ability to multi-program.
A single program cannot, in general, keep either the CPU or the I/O devices busy at all times.
Single users frequently have multiple programs running.
Multiprogramming needed for efficiency
Multiprogramming organizes jobs (code and data) so CPU always has one to execute
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.
The set of jobs in memory can be a subset of the jobs kept in the job pool.
The operating system picks and begins to execute one of the jobs in memory.
The job may have to wait for some task, such as an I/O operation, to complete.
In a non-multi programmed system, the CPU would sit idle.
In a multi programmed system, the operating system simply switches to, and executes, another job.
Timesharing (multitasking) is a logical extension to multiprogramming
o The CPU switches jobs so frequently that users can interact with each job while it is running, creating interactive
computing
o Response time should be short (typically < 1 second)
o Each user has at least one program executing in memory { Process }
o If several jobs are ready to run at the same time, the system must choose which job will run first. Making this
decision is { CPU scheduling }
o If processes don’t fit in memory, swapping moves them whereby processes are swapped in and out of main
memory to the disk to run
o Virtual memory allows execution of processes not completely in memory
Page 6 of 10
1.6 Process Management
A process is a program in execution.
o It is a unit of work within the system
o Program is a passive entity, process is an active entity
Process needs resources to accomplish its task
o CPU, memory, I/O, files
o Initialization data
Process termination requires reclaim of any reusable resources
Single-threaded process has one program counter specifying location of next instruction to execute
o Process executes instructions sequentially, one at a time, until completion
Multi-threaded process has one program counter per thread
Typically a system has many processes running concurrently on one or more CPUs
o Some user processes and others system processes
o Concurrency by multiplexing the CPUs among the processes / threads
The operating system is responsible for the following activities in connection with process management:
o Creating and deleting both user and system processes
o Scheduling processes and threads on the CPUs
o Suspending and resuming processes
o Providing mechanisms for process synchronization
o Providing mechanisms for process communication
o Providing mechanisms for deadlock handling
3. Distributed
a. Collection of separate, possibly heterogeneous, systems networked together
b. Network is a communications path, TCP/IP most common
c. Local Area Network (LAN)
d. Wide Area Network (WAN)
e. Metropolitan Area Network (MAN)
f. Personal Area Network (PAN)
g. Network Operating System provides features (as file sharing) between systems across network
h. Communication scheme allows systems to exchange messages
i. Impression of a single system
4. Client-Server Computing
a. Dumb terminals supplanted by smart PCs
b. Many systems now servers, responding to requests generated by clients
c. Compute-server system provides an interface to client to request services (i.e., database)
d. File-server system provides interface for clients to store and retrieve files
5. Peer To Peer
a. Another model of distributed system
b. P2P does not distinguish clients and servers
c. Instead all nodes are considered peers
d. May each act as client, server or both
e. Node must join P2P network
i. Registers its service with central lookup service on network, or
ii. Broadcast request for service and respond to requests for service via discovery protocol
f. Examples include Napster and Gnutella, Voice over IP (VoIP) such as Skype
6. Virtualization
a. Allows operating systems to run as applications within other OSs
i. Vast and growing industry
Page 9 of 10
b. Emulation used when source CPU type different from target CPU type (i.e. PowerPC to Intel x86)
i. Generally slowest method
ii. When computer language not compiled to native code – Interpretation
c. Virtualization – OS natively compiled for CPU, running guest OSs also natively compiled
i. Consider VMware running WinXP guests, each running applications, all on native WinXP
host OS
ii. VMM provides virtualization services
d. Use cases involve laptops and desktops running multiple OSs for exploration or compatibility
i. Apple laptop running Mac OS X host, Windows as a guest
ii. Developing apps for multiple OSs without having multiple systems
iii. QA testing applications without having multiple systems
iv. Executing and managing compute environments within data centers
e. VMMs can run natively, in which case they are also the host
7. Cloud Computing
a. Delivers computing, storage, even apps as a service across a network
b. Logical extension of virtualization as based on virtualization
i. Amazon EC2 has thousands of servers, millions of VMs, PBs of storage available across
the Internet, pay based on usage
c. Cloud compute environments composed of usual OSs plus VMMs and cloud management tools
i. Internet connectivity requires security like firewalls
ii. Load balancers spread traffic across multiple applications
d. Many types
i. Public cloud – available via Internet to anyone willing to pay
ii. Private cloud – run by a company for the company’s own use
iii. Hybrid cloud – includes both public and private cloud components
iv. Software as a Service (SaaS) – one or more applications available via the Internet (i.e.
word processor)
v. Platform as a Service (PaaS) – software stack ready for application use via the Internet
(i.e a database server)
vi. Infrastructure as a Service (IaaS) – servers or storage available over Internet (i.e. storage
available for backup)
8. Real time embedded system
a. Real-time embedded systems most prevalent form of computers
i. Vary considerable, special purpose, limited purpose OS, real-time OS
ii. Usually have little or no user interface
b. Many other special computing environments as well
i. Some have OSs, some perform tasks without an OS
c. Real-time OS has well-defined fixed time constraints
i. Processing must be done within constraint
ii. Correct operation only if constraints met
Page 10 of 10
Chapter Two OS
(System services)
Initial program loader: The system must be able to load a program into memory and to run that
program, end execution, either normally or abnormally
Resource allocation.
» Processmanagement
» Memory management
» Secondary storage management
Accounting Information .Keep track of which users use how much and what kinds of
computer resources.
Protection and security The owners of information stored in a multiuser or networked
computer system may want to control use of that information, concurrent processes should not interfere
with each other
» Protection involves ensuring that all access to system resources is controlled
» Security of the system from outsiders requires userextends to defending external I/O devices from
invalid access attempts
System Calls
Programming interface to the services provided by the OS
Typically written in a high-level language (C or C++)
Types of System Calls
Process control
File management
Device management
Information maintenance
Communications
Operating system structure
1- Simple Structure
MS-DOS – written to provide the most functionality in the least space
Not divided into modules
Although MS-DOS has some structure, its interfaces and levels of functionality are not well
separated
A set of service procedures that carry out the system calls.
A set of utility procedures that help the service procedures.
2- Layered Approach
The operating system is divided into a number of layers (levels), each built on top of lower
layers. The bottom layer (layer 0), is the hardware; the highest (layer N) is the user interface
layers are selected such that each uses functions (operations) and services of only lower-
level layers
3- Virtual Machines
A virtual machine takes the layered approach to its logical conclusion.
It treats hardware and the operating system kernel as though they were
all hardware
A virtual machine provides an interface identical to the underlying bare
hardware
The operating system creates the illusion of multiple processes, each
executing on its own processor with its own (virtual) memory
The resources of the physical computer are shared to create the virtual machines
CPU scheduling can create the appearance that users have their own processor
Spooling and a file system can provide virtual card readers and virtual line printers
A normal user time-sharing terminal serves as the virtual machine operator’s console
Objectives of the chapter
An operating system provides the environment within which programs are executed.
The design of a new operating system is a major task.
It is important that the goals of the system be well defined before the design begins. These goals form the basis for
choices among various algorithms and strategies.
We can view an operating system from several vantage points.
o One view focuses on the services that the system provides;
o another, on the interface that it makes available to users and programmers;
o a third, on its components and their interconnections.
In this chapter, we explore all three aspects of operating systems, showing the viewpoints of users, programmers, and
operating system designers.
We consider what services an operating system provides, how they are provided, how they are debugged, and what the
various methodologies are for designing such systems.
Finally, we describe how operating systems are created and how a computer starts its operating system.
process control
file manipulation
device manipulation
information maintenance
communications
Protection.
2.4.6 Communications
A. create, delete communication connection
B. Message passing model send, receive messages to host name or process name
C. From client to server
D. Shared-memory model create and gain access to memory regions
E. transfer status information
F. attach and detach remote devices
2.4.7 Protection
A. Control access to resources
B. Get and set permissions
C. Allow and deny user access
File management
o These programs create, delete, copy, rename, print, dump, list, and generally manipulate files and
directories.
Status information.
o Some programs simply ask the system for the date, time, amount of available memory or disk space,
number of users, or similar status information. Others are more complex, providing detailed
performance, logging, and debugging information.
o Typically, these programs format and print the output to the terminal or other output devices or files or
display it in a window of the GUI.
o Some systems also support a registry, which is used to store and retrieve configuration information.
File modification.
o Several text editors may be available to create and modify the content of files stored on disk or other
storage devices.
o There may also be special commands to search contents of files or perform transformations of the text.
Programming-language support.
o Compilers, assemblers, debuggers, and interpreters for common programming languages (such as C,
C++, Java, and PERL) are often provided with the operating system or available as a separate download.
Program loading and execution.
o Once a program is assembled or compiled, it must be loaded into memory to be executed.
o The system may provide absolute loaders, relocatable loaders, linkage editors, and overlay loaders.
Debugging systems for either higher-level languages or machine language are needed as well.
Communications.
o These programs provide the mechanism for creating virtual connections among processes, users, and
computer systems.
o They allow users to send messages to one another’s screens, to browse Web pages, to send e-mail
messages, to log in remotely, or to transfer files from one machine to another.
Background services.
o All general-purpose systems have methods for launching certain system-program processes at boot
time.
o Some of these processes terminate after completing their tasks, while others continue to run until the
system is stopped.
o Provide facilities like disk checking, process scheduling, error logging, printing
o Run in user context not kernel context
o Known as services, subsystems, daemons
2.6.3 Implementation
Much variation
o Early OSs in assembly language
o Then system programming languages like Algol, PL/1
o Now C, C++
Actually usually a mix of languages
o Lowest levels in assembly
o Main body in C
o Systems programs in C, C++, scripting languages like PERL, Python, shell scripts
More high-level language easier to port to other hardware , But slower
Emulation can allow an OS to run on non-native hardware
With modularity, layers are selected such that each uses functions (operations) and services of
only lower-level layers
o Microkernel System Structure
Moves as much from the kernel into user space
Mach example of microkernel
Mac OS X kernel (Darwin) partly based on Mach
Communication takes place between user modules using message passing
Benefits:
Easier to extend a microkernel
Easier to port the operating system to new architectures
More reliable (less code is running in kernel mode)
More secure
Detriments:
Performance overhead of user space to kernel space communication
o Modules
Most modern operating systems implement loadable kernel modules
Uses object-oriented approach
Each core component is separate
Each talks to the others over known interfaces
Each is loadable as needed within the kernel
Overall, similar to layers but with more flexible
Linux, Solaris
The Solaris operating system structure, shown in Figure , is organized around a core
kernel with seven types of loadable kernel modules:
a. Scheduling classes
b. File systems
c. Loadable system calls
d. Executable formats
e. STREAMS modules
f. Miscellaneous
g. Device and bus drivers
Linux also uses loadable kernel modules, primarily for supporting device drivers and
file systems.
o Hybrid Systems
Very few operating systems adopt a single, strictly defined structure.
Instead, they combine different structures, resulting in hybrid systems that address
performance, security, and usability issues.
Hybrid combines multiple approaches to address performance, security, usability needs
Linux and Solaris kernels in kernel address space, so monolithic, plus modular for dynamic
loading of functionality
Windows mostly monolithic, plus microkernel for different subsystem personalities
Examples:
Mac OS X :
a. The Apple Mac OS X operating system uses a hybrid structure
b. It is a layered system. The top layers include the Aqua user interface and a set
of application environments and services.
c. Notably, the Cocoa environment specifies an API for the Objective-C
programming language, which is used for writing Mac OS X applications.
d. Below these layers is the kernel environment, which consists primarily of the
Mach microkernel and the BSD UNIX kernel.
IOS
a. Apple mobile OS for iPhone, iPad
b. Structured on Mac OS X, added functionality
c. Does not run OS X applications natively
d. Also runs on different CPU architecture (ARM vs. Intel)
e. Cocoa Touch Objective-C API for developing apps
f. Media services layer for graphics, audio, video
g. Core services provides cloud computing, databases
h. Core operating system, based on Mac OS X kernel
Android
a. Developed by Open Handset Alliance (mostly Google)
1. Open Source
b. Similar stack to iOS
c. Based on Linux kernel but modified
1. Provides process, memory, device-driver management
2. Adds power management
d. Runtime environment includes core set of libraries and Dalvik virtual machine
1. Apps developed in Java plus Android API
Java class files compiled to Java bytecode then translated to
executable than runs in Dalvik VM
e. Libraries include frameworks for web browser (webkit), database (SQLite),
multimedia, smaller libc
Ostaz Online
http://www.facebook.com/Ostaz.Online
األٚي وذٖ لثً اٌسالَ :إْ اٌطشذ دٖ ِص ػٍطاْ ذزاوش ِٕٗ وً زاخح الالال دٖ ػٍطاْ تس ذف ِٕٗ ُٙاٌٍيٍح وٍٙا
ٚاٌغّٛؼ اٌٍي في االساليذ ٚذمذس ذسرٛػة االساليذ ِاضيح اصاي ٚوذٖ ٌىٓ اويذ ِص ٘رمذس ذسً زاخح في
االِرساْ ِٓ اٌٍّخع دٖ ا ِٓ ٚاٌطشذ دٖ
الفصل الثالث
العمليات
األٚتيشاذيٕح سيسرُ ٌّا تيدي يطرغً ػٍي اٌدٙاص ػادي تيمؼذ يشغي في ٍِي ْٛزاخح غر ؟؟ ازٕا ٕ٘اخذ ُِٕٙ
زاخريٓ :
األٌٚي :زاخح اسّٙا اٌثاذص سيسرُ ٚدٖ اذطشذ في ضاترش ٚازذ ٕ٘ٚا اسّٗ خٛتس
ٚاٌرأيح ٍِ :ري تشٚخشاِيٓ سيسرُ ٚدٖ ٘ ٛتشدٖ اسّٗ اٌيٛسش تشٚخشاِض أ ٚاٌراسىس اٌٍي ٘ي اٌّّٙاخ يؼٕي
ذؼشيف اٌثشٚخشاَ ؟؟ دٖ ػثاسج ػٓ زاخح اسراذيه يؼٕي زاخح فيٙا ِدّٛػح ِٓ األٚاِش خا٘ضج أسرشاورطٕض
ترىِ ْٛسذدج ذّاِا ال ترضيذ ٚال ذمً ٚال يسضٔ:D ْٛ
ذؼشيف اٌثشٚسيس ؟؟ دي زاخح ديٕاِيه يؼٕي ِص ثاترح اِ ٚص ِسفٛظح ٘ي تررغيش ِّىٓ ذضيذ ِّٚىٓ ذمً
ٚاٌرؼشيف اٌؼٍّي ٌيٙا تمي ٌّا ٔيدي ٔىٍُ غر ِغ تؼؽ ٘ي ػثاسج ػٓ أي تشٔاِح داخً ػٍي ِشزٍح اٌرٕفيز
ٔمذس ٔمٛي ػٍيٗ تشٚسيس أ ٚػٍّيح
أي غٛسج ٌٍثشٚسيس في اٌّيّٛسي " اٌزاوشج يؼٕي " تيثمي اسّٙا ادسيس اسثيس " ِسازح " ٚتيى ْٛفيٙا
اٌراٌي :ضٛيح ِىٔٛاخ وذٖ ٕ٘مٌٙٛا ِغ تؼؽ :
1
أٚي زاخح :ذىسد سيىطٓ ٚدي تيى ْٛفيٙا اٌىٛد تراع وً اتٍيىاضٓ تيطرغً ،يؼٕي وً اتٍيىاضٓ ٌيٗ وٛد ذّاَ
؟؟ ا٘ا اٚوي يثمي اٌدضء دٖ تيى ْٛفيٗ اٌىٛد تراع االتٍيىاضٓ
ذأي زاخح :داذا سىطٓ ٚدي تيى ْٛفيٙا اٌذاذا اسرشاورطش تراع االتٍيىاضٓ يثمي اٌٍي فاذد فيٙا اٌىٛد ٚدي فيٙا
اٌذاذا اسرشاورطش
ذاٌد زاخح :اٌٙية ٚدي تمي ترى ْٛاٌّيّٛسي اٌٍي تررسدض ػٍطاْ خاطش ػي ْٛاالتٍيىاضٓ ٌىٓ ترى ْٛديٕاِيه
تّؼٕي ذأي تررسدض في اٌشْ ذايُ " ٚلد اٌرطغيً " ٚوّاْ ِص تيىٌ ْٛيٙا ِسازح ِؼيٕح ،تررسدض زسة
اٌساخح ٚذسد أِش سؼادذه $:
ساتغ زاخح تمي ٚاآلخيشج :االسران ٚدي زاخح تٕسط فيٙا ليّح اٌشيديسراس ٚأي ليّح تسرخذِٙا ٌفرشج ِؤلرح ...
طثؼا ذمشيثا وً اٌّفا٘يُ دي ػذيد ػٍيٕا في ِادج اٌذاذا سرشاورطش ٘ٚىزا
اٌّفشٚؼ دٌٛلري اْ ٔظاَ اٌرطغيً ا ٚاالٚتشيرٕيح سيسرُ يٕظُ اٌّٙشخاْ دٖ وٍٗ ٚاٌؼٍّياخ اٌٍي تررُ دي وٍٙا
ذّاَ ؟؟ ذّاَ خذا ،ػٍطاْ وذٖ ٕ٘اخذ تمي ايٗ ضٛيح زاخاخ وذٖ ترىِ ْٛغ اي تشٚسيس ا ٚذمذس ذمٛي ِالصِح
ٌيٙا ػٍطاْ تٕاءا ػٍي اٌساخاخ دي ٕ٘مذس ٔشذة اٌؼٍّياخ تراػرٕا صي إٌاط اٌثٕي آدِيٓ ػادي خذا
فيٗ تس زاخح الصَ ٔثمي ػاسفيٕٙا ٘ٚي إْ وً اٌذاذا خاغح تأي ػٍّيح تررخضْ في زاخح اسّٙا " تشٚسيس
وٕرشٚي تٍٛن " ٚتيرخضْ طثؼا ِغ اٌثشٚسيس ضٛيح زاخاخ ِالصِح ٌيٙا اٌٍي ازٕا لٍٕا ػٍيٙا في اٌسطشيٓ اٌٍي
لثٍُٙ
اٌساخح األٌٚي :اٌثشٚسيس أي دي ٚدٖ تيى ْٛسلُ ئٛيه " ِٛزذ " ِٚص تيرىشس ٚطثؼا اويذ وً ٚازذ دٌٛلري
خٗ في رٕ٘ح اٌثشايّاسي وي تراع اٌذاذا تيض أ ٚستط اٌّػطٍر تساخح
يمذس يفرىشٖ
اٌساخح اٌرأيح :االسريد " اٌساٌح يؼٕي " ٚدي ٕ٘ىٍُ ػٍيٙا ِغ تؼؽ
دٌٛلري تاٌرفػيً وّاْ ضٛيح غغٕٕيٓ ٘ٚثمي افىشوُ تيٙا ٌّا ٔٛغٍٙا
اٌساخح اٌراٌرح :اٌثشيٛسيري " األٌٛٚيح " يؼٕي ِٓ اآلخش وذٖ ِيٓ لثً
ِيٓ ِٚيٓ يذخً األٚي ٘ٚىزا
اٌساخح اٌشاتؼح :اٌثشٚخشاَ وأٚرش " ػذاد اٌثشٔاِح " ٚدٖ تيطاٚس ػٍي
االدسيس ا ٚاٌؼٕٛاْ تراع األِش اٌٍي ػٍيٗ اٌذٚس ُِّّّّ ...طثؼا
ذ٘ٛرٗ ضٛيح ٕ٘ا ...تػٛا اٌؼٍّيح فيٙا وزا أِش غر ؟؟ ذّاَ ّ٘ ،ا
ٚالفيٓ تمي ِثال ٔرخيً وذٖ تاٌذٚس طاتٛس ػٍطاْ يرٕفزٚا في اٌؼٍّيح تس
اويذ ِص الصَ يرٕفزٚا تاٌذٚس ػٍطاْ فيٗ أٌٛٚياخ ذأيح ٕ٘اخذ٘ا في
االػرثاس ف ٛٙخالظ تيسذد ٘يٕفز أٗ اِش في اٌؼٍّيح ٚيم َٛاٌثشٚخشاَ
وأٚرش صي اٌطاطش يشٚذ يمف ا ٚيطاٚس ػٍي االِش اٌٍي ػٍيٗ اٌذٚس
ػٍطاْ يرٕفز
2
اٌساخح اٌخاِسح :سي تي ي ٛسيديسرشص ٚدٖ تيرخضْ فيٙا سيديسرشص " سدالخ تاٌؼشتي " ٌّا يسػً ايشٚس
ِثال في اٌثشٚسيس ػٍطاْ اٌّشج اٌٍي خايح ٌّا يدي ذسػً اٌؼٍّيح ذأي تيىِ ٛ٘ ْٛسدً في اٌشيسدرش
االيشٚس دٖ زػً لثً وذٖ فّص يمغ فيٗ ذأي ٚيخٍي اٌؼٍّيح ذىرًّ تػٛسج غسيسح
اٌساخح اٌسادسح :سي تي ي ٛسىادٚاٌيٕح " خذٚي يؼٕي " أفٛسِيطٓ ٚدي تيى ْٛفيٙا اٌٚيح اٌؼٍّيح اٌثشيٛسيري
ٚدٖ تمي ِىاْ تيرخضْ فيٗ اٌثشيٛسيري تراػري
اٌساخح اٌساتؼح ِ :يّٛسي ِأدّٕد أفٛسِيطٓ ٚدي تمي ترسرٛي ػٍي ِىاْ وً زاخح في اٌّيّٛسي ِٓ اآلخش
وذٖ ترثمي ػاسفح وً زاخح في اٌّيّٛسي ِٛخٛدج فيٓ ٚزافظح اٌؼٕٛاْ تراػٙا
اٌساخح اٌرإِح :أؤٛريٕح أفٛسِيطٓ ٚدي تيرخضْ فيٙا اٌٛلد ٚاٌدٙذ اٌٍي زػً ِٓ اٌثشٚسيسٛس ػٍطاْ يؼًّ
ا ٚيٕفز اٌؼٍّيح دي ُِّّّّّّّ تّؼٕي ذأي أا ِثال ػٕذي زاخح ٘ررٕفز اويذ زػً ػٍيٙا ضٛيح زاساتاخ ِٚص
ػاسف ايٗ ٚسسثد خٙذ ِٓ اٌثشٚسيسٛس ٚٚلد غر ؟؟ غر ،ذّاَ خذا اٌساخاخ دي تمي وٍٙا ترثمي ِرخضٔح
في اٌسرح دي اٌٍي ٘ي اؤٛريح أفٛسِيطٓ
اٌساخح اٌراسؼح :أثٛخ اٚذثٛخ اسراذيٛط أفٛسِاضٓ ٚدي تمي تيى ْٛفيٙا لائّح وذٖ تىً زاخح أا ٘سرخذِٙا
ِٓ االخٙضج خالي اٌثشٚسيس ا ٚاٌؼٍّيح اٌفالٔيح يؼٕي ِثال ػٕذي ػٍّيح ٔمً فيٍُ ٕ٘سرخذَ ِثال ويثٛسد ػٍطاْ
اػًّ وٛتي ا ٚتاسد ٚوذٖ تيىِ ْٛرخضْ فيٙا اسّاء االخٙضج تراػح االٔثٛخ ا ٚاالٚخ تٛخ اٌٍي أد
٘رسرخذِٙا في اٌؼٍّيح دي
اٌساخح اآلخيشج ٚدي تمي ِص ِٛخٛدج في االساليذ تس ا٘ ٛزاخح ٌٍضِٓ وذٖ :D
أٗ أا ػٕذي في آخش وً تشٚسيس وٕرشٚي تٍٛن اٌٍي ازٕا ػّاٌيٓ ٔشغي فيٗ ِٓ اٌػثر دٖ تيى ْٛػٕذي تٛيٕرش
" ِؤضش " تيطاٚس ػٍي اٌثشٚسيس وٕرشٚي تٍٛن اٌٍي ٘يرُ ذٕفيزٖ تؼذي ياسب ذى ٗٔٛفاّ٘يٕٙا ُِّّّّّّّّّّ
ساِغ زذ تيمٛي ِص فاُ٘ تع أا ػٕذي زاخح اسّٙا تشٚسيس وٕرشٚي تٍٛن تيرخضْ فيٙا اٌثشٚسيس ٚوً
زاخح ذثؼٙا غر ؟؟ اويذ ػٕذي ٌىً تشٚسيس تمي تشٚسيس وٕرشٚي تٍٛن ذرخضْ فيٗ فاٌثٛيٕرش دٖ تمي تيطاٚس
ػٍي اٌٍي ٘يرُ ذٕفيزٖ تؼذي ٘ٚىزا
تس ٍِسٛظح ػٍي خٕة وذٖ :اٌثشٚسيس وٕرشٚي تٍٛن تيرخضْ فيٗ وً اٌٍي فاخ دٖ ِا ػذا األٌٚي ِّىٓ يىْٛ
ِرخضْ في ِىاْ ذأي تس ّ٘ا ِص تيثمٛا ِٛخٛديٓ في اٌثشٚسيس وٕرشٚي تٍٛن
دٌٛلري تمي ٕ٘رىٍُ ػٓ زاخح تاٌرفػيً وٕا لٍٕا ػٍيٙا فٛق فاوشيٓ ؟؟ ا٘ا فاوشيٓ اٌدضء اٌرأي ا ٚاٌساخح اٌرأيح
ا ٚاٌّشزٍح اٌرأيح في اٌثشٚسيس وٕرشٚي تٍٛن ٌّا لٍٕا ٕ٘ىٍُ ػٕٙا تاٌرفػيً ٘ٚي " اٌثشٚسيس اسراخ " ....
ٚدي تمي تّدشد إْ اٌثشٚسيس يسػً ٌيٙا اوسيىيٛضٓ " ذطغيً أ ٚاسرذػاء ٌيٙا ػٍطاْ ذطرغً " تررغيش
االسراخ تراػرٙا " اٌساٌح يؼٕي " ٚػٕذٔا تمي ٕ٘ا خّس أٛاع ِٓ اٌساالخ:
إٌٛع األٚي ٔ :ي " ٛخذيذ " ٚدي ِؼٕا٘ا اْ اٌثشٚسيس دي ٌسٗ ِؼٌّٛح خذيذ ٌٚسٗ زذ ػاًِ ٌيٙا وشيد " إٔطاء
" دٌٛلري زاال
إٌٛع اٌرأي :سأيٕح " ذطغيً " ٚدي ِؼٕا٘ا اْ اٌؼٍّيح ضغاٌح دٌٛلري
إٌٛع اٌراٌد ٚ :يريٕح " أرظاس " ٚدي ِؼٕا٘ا اْ اٌثشٚسيس ِسرٕيح زاخح ِؼيٕح ذسػً ػٍطاْ ذىًّ ضغٍٙا صي
ِثال ِٕرظش أثٛخ يذخً ا ٚاٚخ تٛخ يخشج اي ترٕداْ يسػً ٘ٚي ذىًّ ضغٍٙا ػٍي طٛي
3
إٌٛع اٌشاتغ :سيذي " ِسرؼذ ا ٚاالضاسج ٌٙٔٛا اغفش " ٚدي ِؼٕا٘ا اْ اٌثشٚسيس ِسرؼذج إِ ٚرظشج أٙا ذثمي
سأيٕح ِٓ اآلخش اٌشيذي اٚي ِا تيسػً ِؼٕا٘ا صي ِا ذمٛي ايٗ وذٖ أد ٚالف طاتٛس ػٍطاْ ذٕرخة ٚاٌشاخً
ٔادي ػٍي اسّه ترم٘ ٌٗٛا اخي ؟؟ لاٌه الالال خٍيه تس ٚالف أد اٌذٚس اٌٍي خاي
إٌٛع اٌخاِس ٚاآلخيش :ذشِيٕيرذ " إغالق " ِؼٕا٘ا ِٓ اآلخش يا وثيش أٔا خٍػد ٚػاٚص اخٍغ أا =))
اٌطىً دٖ تمي تيمٌٛه ايٗ اٌساالخ اٌٍيُ ِّىٓ ذفرر ػٍي تؼؽ يؼٕي ً٘ ِّىٓ اٌشيذي ذثمي ٔي ٛ؟؟ ٚال اٌؼىس ؟؟
طية ايٗ اٌّشازً اٌٍي ترذخً فيٙا اٌثشٚسيس ؟؟ ٔي ٛاألٚي ٚال ٚال ٚدٖ ٕ٘ؼشفٗ ِٓ اٌطىً دٖ ٚاٌٍي ِص فاُ٘
زاخح ِٓ اٌطىً يثمي يشخغ يشاخغ اٌخّس أٔٛاع اٌٍي فٛق دٚي ذأي صي اٌططٛس وذٖ ػٍطاْ االِرساْ ػاٚص
فِ ُٙغ ضٛيح زفظ ػٍطاْ ذمذس ذؼثش تس تاٌّػطٍساخ ٘ٚي سٍٙح إْ ضاء اهلل
تؼذ وذٖ ٕ٘ذخً في زرح وذٖ صي ِا ذمٌٛٛا ٕ٘ؼًّ ذدشتح تسيطح ٔٛؾر تيٙا ِغ تؼؽ اصاي اٌثشٚسيس ترطرغً
ِغ تؼؿٙا ٚتررٕمً ِٓ تشٚسيس وٕرشٚي تٍٛن
في اٌشسّح دي ػٕذٔا ػٍي اٌطّاي تشٚسيس صيشٚ ٚػٍي اٌيّيٓ تشٚسيس ٚازذ ٚاٌدٙاصيٓ ٌسٗ ٚالفيٓ ،لاَ
اٌدٙاص اٌٍي ػٍي اٌطّاي ػًّ اوسيىيٛخ ٌثشٚسيس ِا " اسرذػاء يؼٕي " فطثؼا ٌسٗ ِفيص تشٚسيسٛس ضغاي
ساذ ػًّ زفظ ٌٍساٌح تراػرٙا ٚفؿً ِسرٕي ضٛيح ٌ ....سذ ِا اٌدٙاص اٌٍي ػٍي اٌيّيٓ خٗ يطرغً لاَ ػًّ
سيٍٛد ٌٍساٌح تراػح اٌثشٚسيس ذأي ٚلاَ اٌدٙاص اٌٍي ػٍي اٌيّيٓ اضرغً ٚفؿً ضغاي ٚتؼذ ِا خٍع ساذ ػًّ
زفظ ٌالسراخ تراػح اٌثشٚسيس ِٓ ذأي ٚفؿً اٌدٙاصيٓ ٚالفيٓ ِص تيؼٍّٛا زاخح ٌٍثشٚسيس دي ِٚص
4
ِسراخيٕٙا دٌٛلري ...أٚي ِا خٗ اٌدٙاص اٌٍي ػٍي اٌطّاي ِسراخٙا ذأي ػٍطاْ يٕفز ضٛيح أٚاِش لاَ ػاًِ
سيٍٛد ذاااأي ٌٍساٌح تراػرٙا ٘ٚىزا
ٌيٗ تمي أا ٚاخغ دِاغىُ تاٌىالَ دٖ وٍٗ ؟؟ ٌٚيٗ ِسراج اورش ِٓ ػٍّيح ا ٚتشٚسيس ؟؟ !!
أٚال ػٍطاْ ػٕذي زاخاخ اسّٙا سيٕدً " فشدي ِغ أٚضح " اتٍيىاضٓ ٚدي ِؼٕا٘ا أي ػٕذي زاخاخ الصَ
ذسػً في ٔفس اٌٛلد صي ِثال سثيً ذطيىش " ِػسر اٌىٍّاخ " ٚدٖ تيطرغً في ٔفس اٌٛلد اٌٍي أا تىرة فيٗ
فأويذ ِسراج اورش ِٓ ػٍّيح ا ٚتشٚسيس
ذأيا ػٕذي زاخاخ ٍِري اتٍيىاضٓ ٚدي ضٛيح ػٍّياخ ترثمي ضغاٌح في اٌخٍفيح صي ِثال ٚازذ تيؼًّ دٍٛٔٚد
ٚسايثٗ أِ ٚثال اٌٛيٕذٚص ِا٘ ٛضغاي ٚأا تىرة
ذاٌد زاخح ٍِري يٛسش ٚدي ِؼٕا٘ا ِثال أي ػٕذي اورش ِٓ يٛسش ضغاي صي دتاسذّٕد " لسُ " وّثيٛذش يؼٕي
ِثال ٌّا ذذخً اٚؾح وذٖ فيٙا اورش ِٓ خٙاص ِّىٓ ذاللي ُٙوٍ ُٙداخٍيٓ ػٍي خٙاص ٚازذ ٚوٍ ُٙضايفيٓ ٔفس
اٌدٙاص ٚوً ٚازذ ضغاي في ِىاْ ِؼيٓ ٘ٚىزا
طية ايٗ تمي اٌساالخ اٌٍي الذس اذٕمً في ِٓ ُٙػٍّيح ٌؼٍّيح ذأيح ؟؟ !! ٕ٘م ٌُٙٛسٛا دٌٛلري
أٚي زاخح :اٌىٍٛن " ساػح " ٚدي ِؼٕا٘ا خذخ اٌٛلد اٌٍي ِسّٛذ ٌيٙا تيٗ
ذأي زاخح :أثٛخ اٚخ تٛخ ٚدي ِؼٕا٘ا أٙا خذخ االٔثٛخ اٌٍي ِسرٕياٖ اِ ٚثال خشخد االٚتد اٌٍي ِطٍٛب
ِٕٙا ٘ٚىزا
ذاٌد زاخح ٚاالخيشج :اْ يى ْٛزػٍٙا ايشٚس فأويذ ِص ٘رىًّ ٘ٚرطٛف اٌٍي تؼذٖ
ػٕذٔا تمي زاخح اسّٙا تشٚسيس سىادٚاٌيٕح " خذٚي " وي " ٛطاتٛس "
ػٕذي ذالخ أٔٛاع ِٓ اٌىي " ٛاٌطٛاتيش " تمذس اغٕف اٌؼٍّيح ػٍي اساسُٙ
أٚي زاخح :اٌدٛب ويٚ ٛدٖ فيٗ وً اٌثشٚسيس اٌٍي ِٛخٛدج في اٌسيسرُ
ذأي زاخح :اٌشيذي ويٚ ٛدٖ فيٗ وً اٌثشٚسيس اٌٍي ِٛخٛدج في اٌّيّٛسي اٌشئيسيح ِٕٚرظشج يسػٍٙا
اوسيىيٛخ " اسرذػاء "
ذاٌد زاخح :ديفيس " خٙاص " ويٚ ٛدي ترطيً اٌثشٚسيس اٌٍي ِٕرظشج أثٛخ ا ٚاٚخ تٛخ دفيس " خٙاص "
5
ٚديٗ تمي ترٛؾر اٌسي تي ي ٛتيرؼاًِ اصاي ِغ اٌىيٛص ٚاٌساخاخ ديٗ:
أٚي ٔٛع ٌٔٛ :ح ذشَ " طٛيٍح اٌّذي " ٚدي اٌٍي ترمشس أٗ ػٍّيٗ ذذخً اٌشيذي ويٚ ٛفي اٌغاٌة ٚلرٙا تيثمي ِٓ
ثٛأي ٌذلايك ٚدٖ ٚلد وثيش طثؼا تإٌسثح ٌٍدٙاص :D
ذأي ٔٛع :اٌطٛسخ ذشَ " لػيش اٌّذي " ٚدي ترمشس أٗ ػٍّيح ٘يسػً ٌيٙا اوسيىيٛخ " اسرذػاء " ٚدٖ ٚلرٗ
تمي تيثمي تاٌٍّي ثأيح ٚدٖ ٚلد لٍيً خذا طثؼا
6
ٔمطح تمي تؼذ وذٖ إْ
اٌساخح األٌٚي :إٔثٛخ أٚذثٛخ تأٚذيذ تشٚسيس ٚدي ِؼٕا٘ا اْ اٌؼٍّيح ترمؿي اورش ٚلرٙا في االٔثٛخ اٚذثٛخ
اورش ِٓ اٌسساتاخ
اٌساخح اٌرأيح :اٌسي تي ي ٛتأٚذ تشٚسيس ٚدي ِؼٕا٘ا اْ اٌؼٍّيح ترمؿي اورش ٚلرٙا في اٌسسثااخ يؼٕي ِٓ
اآلخش وذٖ دي ػىس اٌساخح األٌٚي
اٌّ: ُٙ
اٌساخح األٌٚي فيٙا :اٌثشٚسيس وشيطٓ " أطاء " ِؼٕا٘ا اصاي اػًّ تشٚسيس خذيذج
ٚدي فيٙا استغ زاخاخ الذس اػًّ فيٙا أطاء ٌثشٚسيس خذيذج
1اٌسيسرُ أيطياٌيضاضٓ ٚدي تيمٌٛه ٛ٘ٚاٌسيسرُ ٌسح تيرؼشف اويذ فيٗ تشٚسيس ترٕطأ في اٌٛلد دٖ
2اوسيىيٛضٓ " اسرذػاء " اٚف تشٚسيس ٚ :دي ٌّا اخي اػًّ اوسيىيٛخ " اسرذػاء " ٌؼٍّيح ٚأا اغال
ضغاي في ػٍّيح ذأيح فأويذ اٌؼٍّيح اٌدذيذج اٌٍي أا ٌسٗ ػاًِ ٌيٙا اسرذػاء ترٕطأ ٌسٗ ِٓ خذيذ
3يٛسش سيىٛيسد ٚ :دي ِؼٕا٘ا اْ اٌيٛسش ٘ ٛاٌٍي يطٍة تمي تطشيمح ِثاضشج يمٌٛه أا ػاٚص اػًّ تشٚسيس
خذيذج
7
تػٛا تمي في اٌػٛسج اٌٍي خايح دي تيمٌٛه اْ اٌؼٍّيح اٌٛازذج ٌّا ذثمي تاسٔد " أب " ِّىٓ يثمي ٌيٙا اتٕاء "
ضايٍذ " :D
فٍّا ذيدي ترٕادي ػٍي ػٍّيح ذأيح ِٓ اٌٍي ذسرٙا تيرى ْٛػٕذي اٌطىً دٖ اٌٍي ٘ ٛضىً اٌطدشج أ " ٚاٌرشي "
ذؼاٌٛا وذٖ ٔذسدش ضٛيح في اٌخػائع اٌٍي تيٓ وً أب ٚاتٕٗ " ساِسٕي ياسب "
ِّىٓ االب ٚاالتٓ يؼٍّٛا ضيش ٌىً اٌشيسٛسط ِغ تؼؽ ِّٚىٓ االتٓ يؼًّ ضيش ِٓ زاخاخ ات ٖٛياخذٌٗ
خالتيح ا ٚوذٖ زاخح ػٍي اٌّاضي يؼٕي :D
ِّٚىٓ تمي االذٕيٓ ٍِِٛٙص ػاللح تثؼؽ اساسا يؼٕي ِٓ اآلخش ٌ ٛأد ِطشٚد ِٓ اٌثيد
ِّىٓ االب ٚاتٕٗ يسػٍ ُٙاسرذػاء في ٔفس اٌٛلد ِٚغ تؼؽ " أِٓ دٌٚح "
أِّ ٚىٓ االب يسرٕي ٌسذ ِا اتٕٗ يخٍع " ضٛيح ذؿسيح "
دي تمي اْ االتٓ ِّىٓ يمشس ياخذ ػٕٛاْ ات " ٖٛيردٛص ِؼاٖ :D
طية ٕ٘اخذ ِثاي وذٖ فاوشيٓ طثؼا االسيّٕد اٌٍي وٍٕا ػٍّٕا فيٗ وٛتي ِٓ إٌد =)) تراع اٌّيٕىس اٌٍي اٌذفؼح
وٍٙا سٍّد ٔفس اٌىٛد ؟؟ ا٘ ٛ٘ ٛدٖ وّا ِ٘ٛ ٛؾر في اٌػٛسج اآلذيح :
8
طثؼا وً دٖ تٕىٍُ في اٌؼٍّياخ ػٍي اٌؼٍّياخ ِص ذٕسٛا ٚ :Dلٍٕا أٚي ٔٛع ٚواْ تذاخٍح وً اٌشغي دٖ ٛ٘ٚ
أطاء ػٍّيح خذيذج
ٕ٘مٛي تمي االسثاب اٌٍي ِّىٓ ذؼًّ اغالق " ذشِيٕيطٓ " ألي ػٍّيح
ٔٛسِاي ..يؼٕي ِٓ االخش خشخد طثيؼي أ ٚايشٚس ٚدٖ ٌّا يسػً ايشٚس ٚذخشج ٚضىشا أ ٚتمي فاذً ايشٚس
ٚدٖ ِؼٕاٖ ايشٚس تس فيٗ اٌطفي يؼٕي يخٍي اٌؼٍّيح ذؿشب أِ ٚثال ذيدي ػٍّيح ذأيح ِٓ ٚظيفيرٙا أٙا
ذخٍع ػٍي اٌؼٍّيح اٌٍي ضغاٌح
أٚي ٌّا اٌؼٍّيح ذٕفز آخش زاخح فيٙا ذثؼد ٌٕظاَ اٌرطغيً ٚذم ٌٗٛاػٍّي ذطغيً ٚتيرُ طثؼا اٌىالَ دٖ تطشيمريٓ :
1اٌذاذا ٌّا تيريدي ذخشج ترخشج ِٓ االتٓ ٌالب ثُ ٌالب االوثش ٘ٚىزا يؼٕي وً اب الصَ يسرٕي اتٕٗ ٌّا يخٍع
األٚي
ِّىٓ وّاْ اْ االب يمشس ِغ ٔفسٗ وذٖ أٗ يمفً االتٓ اٌٍي ذسريٗ ٚيؼًّ ٌيٗ ذشِيٕيد ٚدي تيثمي اسّٙا اتٛسخ
اٚي زاخح أذيثيٕذأد تشٚسيس ِؼٕا٘ا تشٚسيس ِسرمٍح ٍِٙاش ػاللح تأي زاخح ال ذأثش ٚال ذرأثش زاخح خاِذج
أخش زاخح
ِّىٓ ا ػًّ فيٙا ضيش ٌٍّؼٍِٛاخ ا ٚوّاْ ِّىٓ ذسشيغ اٌؼٍّيح أدض٘ا يؼٕي تسشػح اٚ ٚس ًٙوّاْ ػٍي
اٌسيسرُ أٗ يمسُ اٌؼٍّيح ا ٚيمسُ اٌّّٙاخ ػٍي اخضاء ٚيمذس يخٍع وً خضء ٌٛزذٖ ٚوّاْ ذّىٓ اٌّسرخذَ أٗ
يطرغً ػٍي ِّٙاخ وريش في ٔفس اٌٛلد
9
فيٗ ِػٍطسيٓ وذٖ ٕ٘مٚ ٌُٙٛاٌثالي ٍِٛٙش اي ذالذيٓ الصَ وّا لاي تاسُ يٛسف
ضيشد ِيّٛسي :دٖ ِىاْ ِطرشن تيٓ اٌؼٍّيريٓ يمذسٚا يطيشٚا ِاتيٓ تؼؽ فيٗ ِثال صي ِا يى ْٛػٕذي
تشٚسيس ٚازذ ٚتشٚسيس اذٕيٓ ،تشٚسيس ٚازذ ػٍّد تيأاخ ِؼيٕح ٚتشٚسيس اذٕيٓ ِسراخح ذمشأ اٌثيأاخ دي
فرم َٛاٌثياأاخ دي ذذخً في اٌطيشد ِيّٛسي ػٍطاْ االذٕيٓ يمذسٚا يطٛف٘ٛا
1أْ تأٚذيذ تافش ٚ :دٖ تيسّر ٌٍّسرخذَ أٗ يؼًّ ػٍّياخ غيش ِسذٚدج إلْ زدّٗ غيش ِسذٚد
2ذأي زاخح اٌثأٚذيذ تافش :تيسذدٌي ِسازح ِؼيٕح تس ػٍي لذ ِا اٌثشٚسيس االٌٚي ذٕردٗ ػٍي لذ ِا
اٌثشٚسيس اٌرأيح ذسرٍٙىٗ ٚتس وذٖ
اٌّػطٍر اٌرأي :اٌّاسح تاسيٕح ٚدي اٌطشيمح اٌرأيح اٌٍي الذس اػًّ تيٙا ضيشيٕح تيٓ اٌؼٍّياخ ٚتؼؿٙا
ٚدٖ تيرُ ذثادي اٌشسايً تيٓ اٌؼٍّياخ فيٗ ػٓ طشيك االذػاي ِغ تؼؽ ِٓ غيش ٚخٛد ِىاْ ِطرشن يؼٍّٛا فيٗ
ضيش ٌٍذاذاخ ِغ تؼؽ ٚيى ْٛطثؼا زدُ اٌساخاخ دي ثاتد ٚتشدٖ ػٍطاْ يثؼرٛا اٌساخاخ دي ترّش ػٍي
اٌىشٔاي " " ٚ kernelتيرُ إٌمً ػٓ طشيك ٔٛػيٓ ِٓ اٌشسايً :
1سٕذ 2ٚسسيف سٍُ ٚاسرٍُ يؼٕي ٚ ػٍطاْ يثمي فيٗ اذػاي تيٓ اي ػٍّيريٓ الصَ يثمي ػٕذن زاخريٓ :
1أٚي زاخح الصَ يى ْٛفيٗ ٚسيٍح اذػاي تيٕ 2 . ُٙاْ يى ْٛفيٗ ذثادي سسايً تيُٕٙ
تالي اٌطاترش فيٗ ذالذح اساليذ تيٛؾسٛا االذػاي اٌّثاضش ٚاٌغيش ِثاضش ِا تيٓ اٌؼٍّياخ ٚتؼؽ ٚس ًٙخذا ِٓ
االساليذ
10
Chapter Three OS
Process Concept
Process is a program in execution
Program is a(Static) set of insrtuctions which used as the basis of the process
Program became process when it executed and loaded in the memory and become an
activity entity
The process image in the memory call the process's address space that have
Process information
Some information is associated with the process like (Identifier , satet , priority ,
program counter , memory pointers , I/O status informations )
Process state
States of the process
I/O-bound process– spends more time doing I/O than computations many short CPU
bursts
CPU-bound process– spends more time doing computations; few very long CPU
bursts
Operation on process
1- Process Creation
System initialization
Execution of a process creation system call by a running process
A user request to create a new process
Initiation of a batch job
Parent process create children processes which also create their children processes
forming a tree of processors
Resource sharing
Parent and children share all resources
Children share subset of parent’s resources
Parent and child share no resources
Execution
Parent and children execute concurrently
Parent waits until children terminate
Address space
Child duplicate of parent
Child has a program loaded into it
2- Process Termination
Normal exit (voluntary).
Error exit (voluntary).
Fatal error (involuntary).
Killed by another process (involuntary).
When process finishes its work ask OS to delete it (Exit)
Child sends output to parent via waitning
Process resources are allocated
Parent may terminate child process
Child has exceeded allocated resource
Task assigned to child is no longer required
When parent exiting some OS's do not allow to children to continue their work
Cooperating Processes
Independent process cannot affect or be affected by the execution of another process
Cooperating process can affect or be affected by the execution of another process
Advantages of process cooperation
Information sharing
Computation speed-up
Modularity
Convenience
Shared Memory
Producer Consumer Problem
process produces information that is consumed by a consumer process
unbounded-buffer places no practical limit on the size of the buffer
bounded-buffer assumes that there is a fixed buffer size
Message system – processes communicate with each other without resorting to shared
variables
IPC facility provides two operations:
Send message message size fixed or variable
Receive message
If P and Q wish to communicate , they need to establish a communication link
exchange messages via send/recieve
Implementation of communication link
physical (e.g., shared memory, hardware bus
logical (e.g., logical properties)
Direct Communication
Processes must name each other explicitly:
Properties of communication link
Links are established automatically
A link is associated with exactly one pair of communicating
Between each pair there exists exactly one link
The link may be unidirectional, but is usually bi-directional
Indirect Communication
Messages are directed and received from mailboxes
Each mailbox has a unique id
Processes can communicate only if they share a mailbox
Properties of communication link
Link established only if processes share a common mailbox
A link may be associated with many processes
Each pair of processes may share several communication links
Link may be unidirectional or bi-directional
Operations
create a new mailbox
send and receive messages through mailbox
destroy a mailbox
Primitives are defined as:
Send (A,Message) send message to mailbox A
Recieve (A,Message) recieve message from mailbox A
Mailbox sharing
P1,P2, and P3 share the same Mailbox
P1 Sends and P2 , P3 Recieve
Who gets the Message ?
Allow a link to be associated with at most two processes
Allow only one process at a time to execute a receive operation
Allow the system to select arbitrarily the receiver. Sender is notified who the
receiver was
Operating System
Chapter 5 - Scheduling
Ostaz Online
http://www.facebook.com/Ostaz.Online
Chapter 5: CPU Scheduling
ط١ب لبً ِا ٔبذأ ف ٟاٌشابخز دٖ ,ف ٟش٠ٛت conceptsالسَ ٔى ْٛػارفٕٙ١ا ف ٟاالٚي
٠ؼٕ ٟف ٟاٌٛالغ اصال اْ سِاْ واْ اٌـ ٕ١ِ processorفؼش ٠شخغً ف process ٟجذ٠ذة اال ٌّا ٠خٍص اٌٍٟ
ب١ؼٍّٙا ,اِا دٌٛلخ ٟفـ اٌـ multiprogrammingدٖ ب١اخذ وً اٌـ processesاٌٍ ٟاٌّفزٚض حخُ ٕ٠ ٚفذ
ش٠ٛت ٕ٘ا ٚش٠ٛت ٕ٘ا ٘ ٚىذا ...
حٕف١ذ ا process ٞب١خى ِٓ ْٛحاجخ ٓ١اال ٟ٘ ٌٟٚاٌؼًّ داخً اٌـ ٚ CPUاٌخأ١ت اٌٍ ٟ٘ ٟأخظار ٌٍـ ٚ I/O
حفضً اٌحٍمت د ٗ٠شغاٌت وذٖ ٌخا٠ت ِا اٌـ Processesحخٍص ٚ ,د ٗ٠صٛرة حٛضحٍٕا اٌـ loopاوخز
1
ٗ٠ ٌّذة لذ اٚ ًشخغ١٘ ٟ اِخٚ ًشخغ١٘ ٌٍٟٓ ا١ِ مزر٠ system اٌـٟٔ اٟ٘ Scheduling ت ٌٍـ١اٌفىزة االساس
.. فضً شغاي١٘
CPU Scheduler
.اٙ١ٍشخغً ػ٠ CPU اٌـٍٟض اخٚ ِفزٌٍٟ اprocess ٟٙٔ اready queue ٓ اٌـ١خخار ِٓ ب١ بٌٍٟ اٛ٘ ٟدٖ بم
ٟ طبؼا فٚ , non-preemptive ٟبم١٘ ٖا دٙ ساػخٟبم٠ اٌزابغٚي اٚع االٌٕٛ اٟ واْ فٌٛ scheduling اٌـ
.preemptive ٟبم١٘ اعٛٔ االٟبال
Preemptive
.ت١ٔ حاprocess ًذخ٠ ٚ اٙخزج٠ processor ِّىٓ اٌـٟٕؼ٠ processor ٗ ِش بخؼزف ححخىز اٌـ٠ دٚ
Non-Preemptive
.I/O ك٠ا ػٓ طزٙم٠ؼخزض طز٠ ٚت ِا حخٍص خاٌص ا٠ ٌغاProcessor بخحخىز اٌـٌٍٟ اٟٗ بم٠ دٚ
Dispatcher
ٍٝخضّٓ ػ٠ ٘ذاٚ , Short-term scheduler اخخار٘اٟت اٌخ١ٍّخحىُ باٌؼ٠ CPU مت حجؼً اٌـ٠طز
Switching context
Switching to user mode
Jumping to the proper location in the user program to restart that
program.
Dispatch latency
.ٜت أخز١ًٍّ ػ١اٌبذأ بخشغٚ ت١ٍّلف ػٌٛ ًسخغزلٗ اٌّزس٠ ٞلج اٌذٌٛ اٛ٘
Aim of Scheduling
CPU utilization
اٌٙخُ اسخغال١ٌ ٌْٗ بمذر االِىاٛ ِشغCPU ْٛ حىٟٕؼ٠ , اث١ٍّذ اٌؼ١ حٕفٟ فCPU لجٚ ًاسخغالي و
.ًاالسخغالي األِث
Throughput
2
حبِ ّٓ١ؼذي اٌؼٍّ١اث اٌخّ٠ ٟىٓ أجاس٘ا فٚ ٟلج ِؼِ , ٓ١ثال أا اػزف أفذ بّؼذي 4ػٍّ١اث ف 3 ٟثٛأ.ٟ
) Turnaround time (TAT
اٌٛلج اٌالسَ ٌخٕف١ذ ػٍّ١ت ِا ( اٌٛلج اٌّسخغزق ِٓ بذا٠ت حٕف١ذ اٌؼٍّ١ت إٌٙٔ ٝا٠خٙا).
اٌؼٍّ١ت ِّىٓ اْ حى single CPU burst ْٛا ٚلذ حى ْٛجشء ِ , threadثاي :ابخذأ اٌؼٍّ١ت ف ٟاٌثأ١ت اٌثاٌثت
ٚأخٙج ف ٟاٌثأ١ت اٌسابؼت اٌٛلج اٌالسَ ٌخٕف١ذ ٘ذٖ اٌؼٍّ١ت ٘ 4 ٛثٛأ.ٟ
Waiting time
٘ ٛاٌٛلج اٌذ ٞحسخغزلٗ اٌؼٍّ١ت ف ٟاالٔخظار داخً ready queueلبً دخٌٙٛا إٌ.CPU ٝ
Response time
٘ ٛاٌٛلج اٌذ٠ ٞحخاجٗ اٌبزٔاِج ٌبذأ فؼٍ١ا.
ط١ب ف ٗ١بؼذ وذٖ سٍ١ذ 01 ٚ 9دٚي بصٛا فِ ُٙ١افِٛٙ١ش ا ٞحاجت ِش ٚاضحت ..وٍٗ حىٍّٗ ٌٍ ٟفاث
حؼاٌٛا ٔاخذ ِثاي بسزػت ع اٌىالَ دٖ ..أا جا processes ٍٟ٠باٌخزح١ب دٖ ٚاٌـ
burst timeبخاػ ُٙسِ ٞا ِٛجٛد لذإِا
ط١ب أا ٌّا اج ٟادخً اٌـ processesد٘ ٗ٠ذخً اٌٍ ٟجٗ االٚي ٚبؼذ وذٖ اٌٍ ٟجٗ بؼذ٘ ٚ ٗ٠ىذا ...فٙخبمٟ
اٌزسّت باٌشىً دٖ
ٚاٌـ ١٘ average waiting timeبم ٟب١ساِ ٞٚجّٛػ ُٙػٍ ٟػذدُ٘ اٌٍ١٘ (0 + 24 + 27) / 3 ٛ٘ ٟطٍغ
ب١سا.17 ٞٚ
ط١ب أا ف ٟاٌّثاي دٖ ػٕذ wait ٞوخ١ز ا .. ٞٚط١ب ٕ٘ ٚحً اٌّشىٍت د ٗ٠اسا:S ٞ
أا ِّىٓ ارسُ اٌزسّت د ٗ٠باٌشىً دٖ
3
P2 = 0
P3 = 3
ٚاٌـ ١٘ average waiting timeبم ٟب١ساِ ٞٚجّٛػ ُٙػٍ ٟػذدُ٘ اٌٍ١٘ (0 + 6 + 3) / 3 ٛ٘ ٟطٍغ
ب١سا ٚ .3 ٞٚطبؼا اٌفزق وب١ز ب ٚ ٕٗ١ب ٓ١اٌشىً اٌٍ ٟلبٍٗ
ِ ٌٍٟ ٚفّٙش اٌـ algorithmدٖ ِّىٓ ٠خش ع إٌٍ١ه دٖ ١٘ ٛ٘ ٚف ّٗٙاْ شاء اهلل
http://www.slideshare.net/S.AL.Ballaa/fcfs
ٚدٖ ب١١ج ٟف ٗ١وً ِ ٚ processؼا٘ا اٌٛلج اٌٍِ ٟحخاجاٖ ٚباخخار اٌؼٍّ١ت اٌٍٙ١ٌ ٟا ٚلج الً.
إٌٛع االٚي اٌٍ ٚ Non-Preemptive ٛ٘ ٟدٖ ِؼٕاٖ أٗ ِش ٘١س١ب اٌـ processاال ٌّا ٠خٍصٙا ٚبؼذ وذٖ
ّ٠سه اٌٍ ٟبؼذ٘ا.
ٚإٌٛع اٌخأ ٟاٌٍ ٛ٘ ٟاٌـ ٚ Preemptiveدٖ ِؼٕاٖ أٗ ٘١شخغً ػٍ process ٟدٌٛلخٌ ٟىٓ ٌ ٛجاحٍٗ
processحأ١ت الً ف ٟاٌٛلج ٛ٘ ٚشغاي ٘١فىس ٌٍ ٟب١ؼٍّٙا ٠ ٚزٚح ٕ٠فذ اٌٍٚ ٟلخٙا الً ٚبؼذ وذٖ ٠بمٟ
٠زجغ ٌٍ ٟب١ؼٍّٙا حأ.ٟ
طبؼا ح٘ٛخٛا ِٕ .. :D ٟبس خشٛا بزدٖ ع إٌٍ١ه دٖ ػٍِ ٗ١ثاي ػٍ ٟوً ٔٛع ِشزٚح ببساطت جذا
http://www.slideshare.net/guest49057a/sjf
طبؼا أا ػٕذ ٞدٌٛلخٌ priority ٟىً ١٘ ٚ processبم ٟػٕذِ ٞشىٍت ف ٟإٌٛع إٌٍ٘ ٟا دٖ اْ اprocess ٞ
اٌـ priorityبخاػخٙا لٍٍ١ت ٘خخٕفذ ِخاخز اِّ ٚ ٞٚىٓ أل ..بس ف ٗ١حً ِّىٓ ٠حٍٍ ٟاٌّشىٍت د :ٗ٠اْ وً ِا
ٚلج االٔخظار بخاع اٌـ processطاي أا الذر ااسٚد اٌـ priorityبخاػخٙا.
4
ط١ب حؼاٌ ٛبمٔ ٟاخذ إٌٛع اٌثاٌث اٌٍRound Robin ٛ٘ ٟ
ٚإٌٛع دٖ بم ٟب١حذد ٚلج ِؼ ٓ١أل process ٞػشاْ حشخغً ٕ١ِ ٚفؼش
حؼذ ٞاٌٛلج دٖ ٌ ,ىٓ ٌ ٛخٍصج لبٍٗ ٠بم ٟخ١ز ٚبزوت
س ٞاٌّثاي دٖ ِ٘ ٛذٚ ٞلج ٌىً processأٙا حخٕفذ ف ٟحذ الص01 ٟ
.CPU ٘ذٖ اٌخاص١ت حشبٗ ٌٚ FCFSىٓ حخخٍف ػٕٙا إْ ٕ٘ان ٚلج ِحذد ٌخٕف١ذ اٌـ processداخً
5
Chapter Five OS
CPU Scheduling
Operating system Main Goals: interleave the execution of processes to
maximize the processor utilization
Maximize CPU Utilization obtained with multiprogramming
Process execution consists of a cycle of CPU execution and I/O wait
The main idea of scheduling, the system decides:
Who will run
When will it run
For how long
CPU Burst :- Burts frequency increased duration decreased and the opposite is right
CPU Scheduler
Selects from memory a process and allocates the CPU to it
CPU scheduling decisions may take place when a process:
1-Switches from running to waiting state // waitning for I/O Non
2-Switches from running to ready state
3-Switches from waiting to ready
4-Terminates // Non
Scheduling under 1 and 4 is non preemative
Decision Mode
Preemptive:-Currently running process may be interrupted and moved to the Ready
state by the operating system
Allows for better service since any one process cannot monopolize the processor for
very long
Non-preemptive :-Once a process is in the running state, it will continue until it
terminates or blocks itself for I/O
Dispatcher
Dispatcher module gives control of the CPU to the process selected by the short term
scheduler; this involves
switching context
switching to user mode
jumping to the proper location in the user program to restart that program
Dispatcher latency
time it takes for the dispatcher to stop one process and start another running
Scheduling goals
CPU Utilizatin :- Keeps the CPU as busy as possible
Response Time :- amount of time it takes from when a request was submitted until
the first response is produced
Throughput :-Number of processes that complete their execution per time unit
Turnaround time:-amount of time to execute a particular process "the total time of
the process staying in the CPU"
Waiting time:-amount of time a process has been waiting in the ready queue
Quality criteria for scheduling (Algorithm)
Fairness:- each process gets a “fair share” of the CPU
Efficiency: keep the CPU busy
Response time: minimize for interactive users
Turnaround: for batch users (total time of batch)
Throughput: maximal number of processed jobs per unit time
Waiting time: minimize the average over processes
Optimization Critiria
Max CPU Utilization
Max throughput
Min Turnaround Time
Min Waiting Time
Min Response Time
First Come First Served (FCFS) Scheduling
If we have 3 processes P1 , P2 , P3 and all arrice at 0 P1 = 24 P2 = 3 P3 = 3
And P1 started first then P1 wait time = 0 P2 = 24 P3 = 27
Average of Waiting = (0 + 24 + 27 )/ 3 = 17
FCFS means what arrived First do its job and not out of processor till finished
The same example but if P2 first then P3 and last P1 P2 Waiting = 0 P3 = 3 P1 = 6
Average of Waing = (0+3+6)/3 = 3
Arrival Time Ta = time the processor become ready "time when the process enetr
the memory"
Service Time Ts = time spent executing in CPU "Burst Time"
Turnaround Time Tr = total time spent waiting and executing
Shortest job First (SJR) Scheduling
Non Preemptive :- Once the process enter the CPU ca not out till finish its Burst
Time "Finish its Job"
Preemptive :- if a new process arrives with Burst time less than the remaining time
of the current process preempt this schema know as Shortest-Remaining-Time-
First (SRTF)
SJF is optimal :- Givest he minimum average waiting time
Priority Scheduling
A priority number (integer) is associated with each process
The CPU is allocated to the process with the highest priority
smallest integer = highest priority
SJF is a priority scheduling where priority is the predicted Next CPU burst time
Problem :- Starvation "Low priority processes may never execute"
Solution :- Aging as time progresses increase the priority of the process
Round Robin (RR)
Each process gets a small unit of CPU time time quantum usually 10-100 milliseconds.
After this time has elapsed, the process is preempted and added to the end of the
ready queue
If there are N processes in the ready queue and the time quantum is q , then each
process gets 1/n of the CPU time in chunks of at most q time units at once. No
process waits more than ( n= 1 ) q time units
When Q is small there will be more switching and overhead is too high
Example of RR with quantum 20 P1 = 53 P2 = 17 P3=68 P4=24
P1 "20"-P2"37"-P3"57"-P4"77"-P1"97"-P3"117"-P4"121"-P1"134"-P3"154"-P3"162"
Typically, higher average turnaround than SJF, but better Response
When Quantum is so low Context Swtich time is so high look page 20
Multilevel Queue
Ready queue is partitioned into separate queues:-
foreground (interactive)
background (batch)
Each queue has its own scheduling algorithm:-
foreground – RR
background – FCFS
Scheduling must be done between the queues :-
Fixed priority scheduling; (i.e., serve all from foreground then from background).
Possibility of starvation.
Time slice each queue gets a certain amount of CPU time which it can schedule
amongst its processes; i.e.,
80% to foreground in RR
20% to background in FCFS
Loog at page 23 for priority of the processes
Multilevel Feedback Queue
A process can move between the various queues; aging can be implemented this way
Multilevel-feedback-queue scheduler defined by the following parameters:
number of queues
scheduling algorithms for each queue
method used to determine when to upgrade a process
method used to determine when to demote a process
method used to determine which queue a process will enter
when that process needs service
Example of Multilevel Feedback Queue
Three queues:
Q0– RR with time quantum 8 milliseconds
Q1– RR time quantum 16 milliseconds
Q2–FCFS
Scheduling
A new job enters queue Q0 which is served FCFS. When it gains CPU, job receives 8
milliseconds. If it does not finish in 8 milliseconds job is moved to queue Q1 at Q1 is
again served FCFS and receives 16 additional milliseconds. If it still does not
complete, it is preempted and moved to queue Q2
Multiple Processor Scheduling
Homogeneous processors within a multiprocessor
Load sharing
Asymmetric multiprocessing:-– only one processor accesses the system data
structures, alleviating the need for data sharing
Real Time Scheduling
Hard real-time:-systems – required to complete acritical task within a guaranteed
amount of time
Soft real-time:-computing – requires that critical processes receive priority over less
fortunate ones
Thread Scheduling
Local Scheduling – How the threads library decides which thread to put onto an
available LWP
Global Scheduling – How the kernel decides which kernel thread to run next
Example:
The following 4 processes arrive in the ready queue at the times shown and have
service (CPU burst times also as shown:
P1 AT=0 ST=8 P2 AT=2 ST=2 P3 AT=3 ST=5 P4 AT=5 ST=1
For each of the following scheduling methods (RR ,with T=2"Qunatum" and SJF) give:
(i) a timing chart to illustrate the execution sequence
(ii) the average job turnaround time
(iii) the waiting time for each job
Assume the overhead of context switching is one time unit
turnaround time "the total time of the process in the CPU"
overhead of context switching "how much time it take to switch from process to other"
PS the new comer in RR system enter in the end of the queue
P1 is processing then P2 arrive and enter the ready queue . P3 arrives but yet P1 didnt
fully get out as it arrived at context switching time so P3 after P2 then P1 out and P2
enter the Processor so P1 will be after P3
OSTAZ ONLINE
ostazonline
2012
Operation System1
بسم هللا الرحمن الرحيم
"المرؤ علي دين خليله فلينظر احدكم من يخالل" صدق رسول هللا صلي هللا عليه وسلم
مالحظات :
هذا الشرح اجتهاد شخصي وليس رسميا
الناشر ليس مسؤال قانونيا عن الشرح
ال غني عن المذاكرة من االسليد او الكتاب
ال تنسوا الدعاء لمن قام بهذا العمل
اذا ذاكرت شيئا ولم تقهم ال تتردد في السؤال
اذا اردت ان تسأل فسأل علي صفحة استاذ اون الين في ال Discussion Board
حاول ان تقرأ وردا من القران قبل المذاكرة حتي يفتح هللا عليك
حاول ان تساعد بأي شيئ حتي لو كان صغييرا
ال تنس ان هللا في عون العبد ما كان العبد في عون اخيه
https://www.facebook.com/Ostaz.Online?sk=wall
السالم عليكم
نفتكر مع بعض شبتر 3وال co operating processesاللي هيا معانا العمليات اللي معتمده
علي بعضها زي ايه؟؟مثال عمليه ال pasteمعتمده انها بتقرا الحجات اللي موجوده جوا
ال bufferاللي انا مليته بعمليه ال... copyطيب نفتكر بقي التعريف بالظبط كان ايه
كل كالممنا في الشبتر داه هيبقي علي العمليات اللي بتبادل المعلومات عن طريق shared
memoryولو مش فاهم يعني ايه ارجع شبتر 3
نبدا بقي بشويع تعريفات قد تكون مش مهمه بس الزم تفهمها عشان تفهم الشبتر
زي ايه مثال زي المثال اللي واحد بيسحب فلوس من البنك والتاني بيسحب نفس الفلوس عن
طريق ال ATMفمفروض الرصيد بيقل بس المكنه لسه ما كانتش شافت ان الرصيد قل مثال او
مثال هنقول ان انا جاي اقرا variableمعين وقريته قبل ما تتكتب عليها القيمه اللي مفروض
اقراها فبيبقي فيه كذا نسخه متغيره للبيانات بتعتي وانا مفروض اقرا نسخه معينه او update
معين ويكون لسه ما اتكتبش او اتكتب عليه updateغيره
يعني بيبقي البرنامج االوالني ماسك في ال( resourceأ) والبرنامج التاني ماسك في
( resourceب) والبرنامج االول مش هيسيب ال resourceبتاعه اال اما ياخد (ب) و
البرنامج التاني مش هيسيب ال resourceبتاعه اال اما ياخد (أ) وبكده وال واحد فيهم هينفذ
الفنكشن بتاعته واالتنين هيقفوا
اني بعمل مشاركه لموارد في اكتر من مكان زي مثال البنك وال ATMودي بتسبب data
inconsistency
االدارة السئيه للموارد وان ما يبقاش فيه حد بيوجه ال processesامتي ديه تقرا وامتي ديه
تكتب وامتي ديه تشتغل بيؤدي الي dead blocks
(اظن بقي عرفتوا قيمه التعريفات اللي فوق ومش هتالقوها غير عندنا)
inدا variableبيقولي ايه المكان الجاي الفاضي اللي ممكن املي فيه حاجه بيصنعها المنتج
countداه بيعبر عن عدد االماكن المليانه في bufferبعتنا (ال bufferهنا ) fixed size
شرح فكرة Consumer
الفكرة ان لو bufferفاضي مش هستهلك اي حاجه واول ما المنتج يماله هستهلك الحاجه ديه
واغير المكان اللي هستهلك منه المرة الجايه وبعدين اقلل ال countعشان خاطر انا كده فيه
مكان كان مليان وبقي فاضي
الفكرة ان لو bufferمليان مش هنتج اي حاجه عشان مفيش مكان احط فيه واول ما المستهلك
يفضي هنتج الحاجه ديه واغير المكان اللي هنتج فيه المرة الجايه وبعدين ازود ال countعشان
خاطر انا كده فيه مكان كان فاضي وبقي مليان
كود consumer
طبعا انا بقوله اشتغل لالبد واستهلك بس لو ال countبزيرو داه معناه ان مفيش اي ااماكن
مليانه يعني مفيش حااجه استهلكها فبخش في لوب فاضيه مبتعملش حاجه (سامع واحد دلوقت
بيقول امتي هنخرج من اللوب ديه مش هيخرج خالص )سؤال جميل ..الفكرة زي ما قلنا ان
هنا في تزامن يعني المنتج والمستهلك شغالين مع بعض فلما المنتج ينتج حاجه ال countهتزيد
و مش هتبقي بصفر وهخرج من اللوب الفاضيه ديه وبس بعدين بقي الحاجه اللي هستهلكها
هحطها عندي وازود المكان اللي هستتهلك منه المرة الجايه
كود producer
طبعا انا بقوله اشتغل لالبد انتج بس لو ال countبتساوي حجم ال bufferداه معناه ان
مفيش اي ااماكن فاضيه يعني مش هنيفع انتج حاجه فبخش في لوب فاضيه مبتعملش حاجه
وبرضه امتي هنخرج ..زي ما قلنا ان هنا في تزامن يعني المنتج والمستهلك شغالين مع بعض
فلما المستهلك يسحب حاجه حاجه ال countهتقل وهخرج من اللوب الفاضيه ديه وبس بعدين
بقي الحاجه اللي هنتجها هحطها في البافر وازود المكان اللي هنتج فيه المرة الجايه
طيب ما هو كالم زي الفل ايه مشكله التزامن بقي ...الااااا دي مشكله كبيره جدا لو الحظنا
بقي اي instructionعشان تتنفذ في ال assembly languageعشان تتنفذ الزم االول
بقرا ال variableمن الذاكره واحطه في registerوبعدين اعمل عليه الشغل بتاعي وبعدين
ارجع اكتبه في الذاكره تاني يعني مثال
count++; #C++
افرض بقي ان اثناء وانا شغال قبل ما اكتب قيمه register1حصلي interruptعشان
حاجه تانيه هتشتغل وانا لسه ما كتبتبش القيمه الجديده يا فالح كده الدنيا هتبوظ وممكن
اكتب برا البافر او اقرا من براه وهيحصل run time errorاو logical errorوحجات كده
ربنا يبعدها عنكو وداه بقي اللي هوا race condition
تعريفات مهمه
للداتا في نفس اللحظه والناتج بتاعaccess يعني دي الحاله اللي عندها عمليتين او اكتر بيعملوا
العمليتين متوقف علي الترتيب اللي هما هيشتغلوا بيه يعني مثال لو نفتكر فوق في كود المنتج
والمستهلك وانا بعمل
count = register1;
قبل ما هيا تتكتب الcount يعني ما يجيش المستهلك ويقراaccessكان الزم اراعي ترتيب ال
كان مفروض يستني لما الحاجه تتنفذ بالترتيب لصح
واللي مفروض ما يخصلش عندهcount++ دا بقي اللي هوا بيبقي كود معين جو العمليه زي
عشان لو حصل ممكن تحصل اي مشكله من اللي قلنا عليها فوق عشان كده اتسميinterrupt
يعني عيل خيطرcritical
طيب فيه حجات الزم بقي اي تكتيك الداره التزامن يحققها واال يترمي في الزباله
1-mutual exclusion
2-progress
3-bounded waiting
اول واحده
يبقي الزم تكملshared والسكشن داهCritical section شغاله فيprocess يعني لو في
وما ينفعش نعلمها انتربت عشان نشغل حاجه تانيه
تاني واحده
بس اللي عايزهprocesses بتاعها يبقي الCS بتشغل الprocess يعني لو دلوقت ما فيش اي
بتاعهCS بتعها هيا بس اللي بتخش في عمليه االختيار مين اللي عليه الدور يشغل الCS تشغل
التانيهprocesses تعيق تقدم الprocess فالبتالي مفيش اي
While(true) {
// critical section
تالت واحده
بتاعهاCS تشغل بيه الprocess يعني الزم يكون في حد معين علي عدد المرات اللي ممكن
تانيه تجوع وما تخشش ابدا يعني لو واحده كل شويه بتشغله وعدتprocesses عشان ما فيش
مرات مثال ال نركنها شويه وبعدين نبقي نرجعلها وهكذا5 الحد اللي هوا
تماااااام قوم بقي يال ذاكر الجزء داه من الساليدز او الكتاب وبعدين كمل النص التاني من
الشبتر النه عايز صحصحه
S/W solution: a code segment that should run before entering critical
section
هههههههههههه طيب خد يا فالح هنا الحل داه عنده عيب كبير جدا ان ال lock
variableداه نفسه اصال يعتبر critical sectionالن افرض الprocesses
وصلوا في نفس الوقت االتنين هيشوفوه بصفر واالتنين هيخشوا ويلبسوا في بعض
اذا الحل داه غير عملي الن مش هنعرف نخلي ال processesان واحد بس يقراه
مش كلهم يقروه في نفس الوقت
2-Peterson solution
يوميها كان تسليم الربورت والناس كانت نايمه اوعوا حد ينام دلوقت
الفكرة انه بيحل مشكله simple lock variableيعني لو اتنين جايين مع بعض في نفس الوقت
واحده بس هيا اللي هتخش والتانيه هتستني طب ازاي؟؟نشوف سوا
P0 P1
I came
Flag[0] = true
Turn = 1
)While(false && true
اللوب ديه بقي مهمه جدا معناها بيقول ايه لو
ال processالتانيه ال flagبتاعها ب true
معني كده انها بتحاول دلوقت تخش الCS
بتاعها طيب تمام و كمان بتقول اللوب ان
الدور علي ال processالتانيه طيب يعني لو
الدور عليها وهيا لما تخلص هتخلي الدوء عليا
فهخرج من اللوب الفاضيه
طيب هنا البروسيس التانيه لسه ما جتش
فال conditionهي failوهخش اعمل الجزء
بتاعي براحتي
Executing crtitical section I came
Flag[1] = true
Turn = 0
)While(true && true
دا معناه ان التانيه لو جاجهزة والدور عليها
هخش في لوب فاضيه ودا اللي هيحصل
Still Executing critical section )While(true && true
لسه في لوب فاضيه
Finished )While (false && true
Flag[0] = false دلوقت هخرج من اللوب الفاضيه واشتغل انا
بقي
يا ريت تعملولها تريسنج تاني مع نفسكوا علورق كده
P0 P1
I came I came
Flag[0] = true Flag[1] = true
Turn = 1 Turn = 0
هنا بقي Turnهيتكتب عليها قيمه واحده بس في االخر مش قيمتين علي حسب انهي اتفذت
االول او انهي بروسيسور خلص قبل التاني وبالتالي الموضوع هيكمل كان واحده جت قبل
التانيه وعادي جدا ونفترض ان القيمه اللي اتكتب بعد كده هيا 1معني كده ان اه االتنين
جاهزين بس الدور المرة الجايه علي واحد يبقي صفر اللي هتتشغل دلوقت
)While(true && false )While(true && true
No wait ;Wait
Executing crtitical section )While(true && true
;Wait
Still Executing critical section )While(true && true
;Wait
Finished )While (false && true
Flag[0] = false No Wait
H/W Solutions:
طيب امتي هخرج من اللوب ديه ؟؟لما حد يخلص ال CSبتاعه ويخلي قيمه المتغير بfalse
طيب اشطه انا دلوقت خالص هخرج من اللوب الفاضيه ديه وهشتغل في CSبتاعي محتاج اني
اخلي المتغير داه ب trueعشان ما حدش يقاطعني ويعدل في شغلي انا وشغال وعشان كده
الفنكشن ديه قبل ما بترجع القيمه بتاعه المنغير بتخليه ب trueعشان لو هوا trueخالص مش
هتفرق لو خليته trueولو هوا falseوالفنكشن اتنده علليها معني كده ان في processهتخش
ال CSبتعها دلوقت ومحتاجه انها تخليه trueعشان ما حدش يقاطعها (نفهم بمثال احسن )
نفترض ان عندي processes 2طيب االولي شغاله عليمين والتانيه علشمال وكل واحده
دلوقت اهيه اديه شغلها
I'm still trying to call it but not now Tmp = lock : OK // False
I must wait TMP = TRUE: OK
Return Tmp : OK // False
// Yes I can call call TAS(lock) // Yes false returned I won't
now because the TAS on the right enter any infinite loop
is finished
Tmp = lock : OK // TRUE I'm executing in my critical section
TMP = TRUE: OK
Return TMP : OK // TRUE
// What the... I can't enter CS now
Tmp = lock : OK // TRUE I'm still executing in my critical
TMP = TRUE: OK section :P
Return TMP : OK // TRUE
// What the... I still can't enter CS
now
Tmp = lock : OK // FALSE I have finished CS now and ill set
TMP = TRUE: OK lock to false
Return TMP : OK // FALSE
// Finally
2-Semaphores
Implementation (binary):
الفكرة بقي ان انا مش هشتغل ابدا اال لو قيمه ال Sبواحد فلو هيا بصفر هخش في لوب فاضيه
ونفس السؤال هيتكرر هخرج امتي ...هخرج لما تيجي اي processتانيه وتزود فيمه الs
وتخليها بواحد عن طريق )( signalطيب انا دلوقت دخلت ولقيت ان قيمه ال Sواحد خالص
هنقص بقي ال Sفهتبقي بصفر عشان اي حد ييجي بعد كده يخش في انفت لوب طيب بعد ما
الحد داه يخرج من االنفنت لوب برضه هيقوم مقلل ال Sعشان هوا هيسنخدمها وهكذا
طبعا ابصم بالعشرة انك مش هتفهم وال كلمه اال لما تعمل tracingزي الكود اللي احنا عاملينه
فوق بتاع ( TestAndSetاعمل انت بقي انا مش هسقيك بمعلقه )
طيب بس برضه مش هسيبك الحل داه مشكلته انك بتخش في لوب فاضيه وديه اسمها busy
waitingحلها ان بدل ما اضيع البروسيسور وكل اللي بيعمله انه مستني ال انا processاللي
تيجي وتالقي انها تستني احطها في طابور بتاع ال processesالي مستنيه ولما واللي بشتغل
تخلص تصحي اي واحده من الطابور داه وداه اللي عملناه في المعمل لو تفتكروا
هتحتاجوا برضه تعمله tracingللكود بايديكوا عشان تفهموا بس لو الناس حاولت وما فهمتش
يبعتولنا علي صفحه استاذ اونالين و احنا نبعتلكوا ازاي تمشوها ان شاء هللا
Chapter Six OS
Synchronization Hardware
Many systems provide hardware support for critical section code
Uniprocessors – could disable interrupts
Currently running code would execute without preemption
Generally too inefficient on multiprocessor systems
Operating systems using this not broadly scalable
It is unwise to give user process the power to turn off interrupts.
Modern machines provide special atomic hardware
Either test memory word and set value
Or swap contents of two memory words
TestAndSet Instructions
read a memory word into a register AND store a nonzero value into that word, in an
indivisible instruction sequence // i think it means that no other instructions can
access this register till its value changes indivisible "unsharable"
Shared boolean variable lock., initialized to false.
Semaphore
Synchronization tool does not require busy waiting
semaphore is a variable that has an integer value
Wait:- operation decrements the semaphore value
Signal:- operation increments semaphore value
If a process is waiting for a signal, it is suspended until that signal is sent
Less complicated
Two standard operations modify S: wait() and signal()
Wait and signal operations are atomic
Signal operation increments semaphore value
Wait operation decrements the semaphore value
Semaphore can only be accessed via two indivisible (atomic) operations// i think it means
that the operation whcih use signal no other operations can use it
Semaphore Usage
Counting
semaphore – integer value can range over an unrestricted domain
May be initialized to a nonnegative number
Binary
semaphore – integer value can range only between 0 and 1; can be simpler to implement
Also known as mutex locks
Provides mutual exclusion
Semaphore Implementation with no Busy waiting
With each semaphore there is an associated waiting queue .
Each entry in a waiting queue has two data items:
value (of type integer)
pointer to next record in the list
Two operations:
block – place the process invoking the operation on the appropriate waiting queue.
wakeup – remove one of processes in the waiting queue and place it in the ready queue.
Implementation of wait: wait (S){
value--;
if (value <0){ add this process to waiting queue
block(); } }
Implementation of signal: Signal (S){
value++;
if (value<=0){ remove a process P from the waiting queue
wakeup(P); }
}}
Classical Problems of Synchronization
Bounded-Buffer Problem
Readers and Writers Problem
Sleeping Barber Problem
Dining-Philosophers Problem
Bounded Buffer-Problem
N buffers, each can hold one item
Semaphore Mutex initialized to the value 1
Semaphore full initialized to value 0
Semaphore empty initialized to value N
Readers Writers-Problem
A data set is shared among a number of concurrent processes
Readers – only read the data set; they dont perform any Updates
Writers – can both read and write.
Problem – allow multiple readers to read at the same time. Only one single writer can access
the shared data at the same time.
Shared Data
Semaphore Mutex initialized to the value 1
Semaphore wrt initialized to the value 1
Integer readcount initialized to 0
Dining Philosophers-Problem
Five philosophers who alternately think and eat Shares a fork with each neighbor
Assume each philosopher picks up left fork,then right fork, then eats
Deadlock if all enter at once
Shared data
Bowl of rice (data set)
Semaphore chopstick [5] initialized to 1
OSTAZ ONLINE
OstazOnline
2012
Operating System -1
بسم هللا الرحمن الرحيم
"افضل الذكر ال اله اال هللا " صدق رسول هللا صلي هللا عليه وسلم
مالحظات :
هذا الشرح اجتهاد شخصي وليس رسميا
الناشر ليس مسؤال قانونيا عن الشرح
ال غني عن المذاكرة من االسليد او الكتاب
ال تنسوا الدعاء لمن قام بهذا العمل
اذا ذاكرت شيئا ولم تقهم ال تتردد في السؤال
اذا اردت ان تسأل فسأل علي صفحة استاذ اون الين في ال Discussion Board
حاول ان تقرأ وردا من القران قبل المذاكرة حتي يفتح هللا عليك
حاول ان تساعد بأي شيئ حتي لو كان صغييرا
ال تنس ان هللا في عون العبد ما كان العبد في عون اخيه
https://www.facebook.com/Ostaz.Online?sk=wall
السالم عليكم
احب اقول بس في االول ان الشتبر داه ما ينفعش تذاكروه من هنا وبس النه مليان حجات
كتير..انا برجح انكم تفهمه من هنا وتذاكره وبعد ما تخلصوه تفتحوا الساليدز بقي او الكتاب
زي ما تحبوا...ربنا معاكوا
طبعا كلنا فاكرين شبتر 5الجميل بتاع الــ CPU Schedulingوعرفنا ان فيه في
processesبتبقي موجوده جوا الــ ready queueو برضه فيه شويه تانيين جوا الــ
blocked queueو هكذا
طيب ما حدش فكر الطوابير ديه موجوده فين ؟؟؟ اه سامعك بتقول موجوده في الـ
Memoryطيب معني كده ان بيحصل sharingللذاكره ديه وبالتالي اكيد محتاجين طرق
لتنظيم الذاكره بتاعتنا وهوا داه اللي بيتكلم عليه الشبتر كله
ديه بقي حته مهمه جدا وهيا اساس كل حاجه في الكمبيوتر دلوقت ...اول ما البرنامج بيفتح
مفروض انه بيحتاج مساحه معينه في الذاكره هنقول مثال محتاج يكون عنده 011عنوان او
011مكان يعني طيب هل الذاكره هتكفي ان كل برنامج ييجي ويستخدم 011مكان في الذاكره
دا احنا لو بنتكلم علي حاجه مثال زي DBMSبكل امكانياتها وتفاصيلها وبابا غنوجها دي
محتاجه علي كده بقي تحمل ال 4جيجا جوا الذاكره من هنا بقي نشات فكره الــ virtual
memoryاللي هنتكلم عليها في شبتر 9ان شاء هللا ان البرنامج مش بيبقي متحمل كله جوا
المموري دا بتبقي الحجات اللي شغاله بس متحمله جوا المموري و احنا هنضحك علي البرنامج
وهنخليه بيبقي فاكر /شايف ادامه ان كل حاجه متحمله
Logical address space: set of all logical addresses generated and seen by
CPU
تبقي موجوده في الlogical مع مالحظه بأكد عليها تاني مش شرط كل حاجه في ال
مثال وبندخلها الذاكره لما البرنامجhard disk ممكن تكون موجوده في الphysical
يحتاجها
يبقي تاني البرنامج بيبقي وهميا شايف ان البرنامج كله متحمل ادامه ولما بيحمل حاجه فيه حد
مسؤول امام البرنامج انه يجبله الجزء المطلوب داه
Program sees virtually that every part is loaded and there is some H/W
responsible for getting the required part
طيب دلوقت بقي مين اللي مسؤول انه يجيب للبرنامج اي حاجه هوا عايزها وكمان بيترجم
دا بقي اسمه (الترجمه هنا يعني تحويل حاجه من نطاق الي نطاقphysical للlogical ال
) mapping اخر اللي هيا كلمه
This H/W part is responsible for mapping logical addresses into physical
addresses
ودا اللي بيقولbase register يعني ايه بقي اللوغارتمات ديه يعني كل برنامج بيبقي ليه
عشانlogical address داه بقي بيتجمع علي الregister البرنامج بيبدا منين في الذاكره ال
physical addressنعرف بالظبط فين مكانه في الذاكره اللي هوا ال
1-Relocation
2-Protection
3-Sharing
4-Physical Organization
اول واحده
لما المستخدم يفتحbinary files علي هيئهhard disk ان البرنامج بيبقي موجود في ال
ان3 ودا يؤكد التعريف بتاع شتبرProcess البرنامج بيتنقل للذاكره ويتحول ل, البرنامج
program in execution هيprocess ال
تاني واحده
تقلب فيprocess للذاكره فداه معناه ان ممكنsharing بتعملprocesses اكيد طالما ال
تانيه وطبعا احنا مش عايزين كده عشان كده الزم اي طريقه من طرق تنظيمprocess ملفات
الذاكره تراعي الحجات ديه عشان تحقق الحمايه
Prevent processes from interfering with each other (no process can
reference any part in any other process without asking it for the
permission)
تالت واحده
مش فاهم منها حاجه ومش موجوده في الكتاب لو حد فاهم منها حاجه يا ريت:رابع واحده
يحط علي صفحه استاذ اونالين
Swappingدلوقت بقي هنتكلم علي مفهوم جديد وهوا ال
عن طريق اننا بندخلrelocation دا بقي هوا الحاجه اللي بنستخدمها عشان نعمل
عايزه تخش ومش القيهprocess اللي البرنامج محتاجها في الذاكره ولو فيهprocess ال
ان شاء هللا9 مكان بنطلع واحده تانيه عن طريق خوارزمات معينه ناقشها في شبتر
Backing store: it's a fast, non volatile and large storage that
must be large enough to accommodate swapped out processes
(it stores any information swapped out from the main
memory), it must provide means for accessing this processes
directly, and backing store is slower and cheaper than the main
memory
So what is a backing store here??? It is the Hard Disk
طيب تماااااااااااااام اقترح دلوقت انك تبص علي الكتاب او االساليدز وتذاكر الجزء داه
وبعديها تنقل علي الجزء التاني من الشبتر اللي هوا
Memory
allocation
mechanisms
B-Non-
A-contiguous
contiguous
1-fixed sized
1-paging
partitioning
2-dynamic sized
2-segmentation
partitionining
اول حاجه الcontiguous
التعريف؟؟
عمنا داه بقي اول ما البرنامج بيشتغل ويتحول ل processبيحجزلها كل المكان اللي هيا عيازاه
في الذاكره وورا بعضه يعني لو برنامج محتاج 011مكان ال MMUهتحجزله 011مكان
وورا بعضهم
في طريقه الترجمه ديه ال logical addressبيبقي عباره عن رقم بيتجمع علي base
registerوداه هيبقي المكان اللي عايز اوصله
طيب الحمايه؟؟protection
طيب واحده واحده كده احنا قلنا ان كل برنامج بيبقي ليه base registerودا اللي بيقول
البرنامج بيبدا منين بالظبط في الذاكره معني كده ان عشان اعمل حمايه انا ما ينفعش اعمل
accessلحاجه مش تبعي خالص هنعمل كمان registerهنحط فيه البرنامج بيخلص فين في
الذاكره واسمه limit register
طيب يبقي عشان ال logicalيترجم صح الزم يكون اكبر من او يساوي ال baseوكمان
اصغر من base + limit
ولو طلع ان ال logicalحاجه غلط يبقي كده بعمل interruptلل OSواقوله ان فيه
addressing errorيعني البرنامج بيحاول يعمل accessعلي حاجه مش متخصصه له
طيب بقي احنا قلنا ان البرنامج بينزل حته وحده كده بس يا تري الحته ديه او ال blockداه اللي
هلنزل فيه هيكون حجمه ثابت وال بيتغير وال ايه
فيه طريقتين
يكون حجم ال blockثابت او يكون حجمه متغير ودا الي بتعمله
Dynamic-sized portioning ودا اللي بتعمله
Fixed sized
partitioning
Memory is divided into variable sized partitions Memory is divided
3 Methods: into fixed sized
1.First fit partitions , that is
Places the process in the first suitable hole partition size must
accommodate theيعني بحط ال processفي اول مكان االقيه ويكون كبير كفايه انه
يستحملها longest possible
2.Best fit program
Places the process in the smallest suitable hole يعني الذاكره بتتقسم
لقطاعات متساويه االحجام يعني بحطها في اصغر مكان كبير O_Oايه داه بقي براحه
يعني بالبلدي كده بنشوف فين االماكن اللي ممكن تستحملها وطبعا الزم القطاع يكون
ونحطها في اصغر مكان فيهم كبير كفايه انه يستحمل
3.Worst fit اكبر برنامج ممكن ييجي
Places the process in the biggest suitable hole
هيا هيا اللي فاتت بس بعد ما بشوف ايه االماكن اللي ممكن
تستحملها بحطها في اكبر مكان فيهم
طيب اكيد كالعاده كل ما ناخد حاجه الزم يطلعوا فيها القطط الفطسانه ويطلع ان ملهاش لزمه
في االخر ايه المشاكل اللي موجوده عموما في اي memory allocation technique
دا دايما بيحصل لما بيكون التقسيم بقسم قطاعات ثابته يعني ايه بقي دلوقت احنا قلنا ان حجم
القطاع ثابت يعني افرض بقي جت processصغيره دلقوت اهيه شغلت المكان ومش هنعرف
نستغله
External fragmentation: total space of holes can fit processes requests
but the space is not contiguous
ودا بيحصل دايما في القطاعات ذات الحجم المتغير dynamicان ال processبتخش وكل
واحده اكيد بتعمل فراغات مثال في ال best fitبيبقي فيه فراغات كتير حطمها صغير وفي
ال worst fitبيبقي فيه فراغات كتيرحجمها كبير والفراغات ديه الحجم الكلي بتاعها بيبقي
يكفي ان processتانيه تيجي تستخجمها بس الفرات ديه مش علي بعضها فكان ملهاش لزمه
ان انا بلم كل الفراغات مع بعضيها عشان استفيد بمكانها داه مع ملحوظه مهمه جداااااااا ان انا
ما ينفعش اعلم compactionاال لو انا بستخدم dynamic memory allocation
هيييييييه برافو عليك انت كده خلصت اكتر من نص الشبتر قوم ذاكر بقي من الكتاب او
التعريف؟؟
هنا بقي ال processمش بيتنزل في حته علي بعضها ال دي بتققسم لكذا قطاع او block
وتنزل في القطاعات ديه ال وايه كمان مش الزم تكون القطاعات ديه متتاليه او contiguous
واضحه يعني .. الذاكره بنقسمها لحاجه اسمها framesفي حاله ال pagingاو
segmentsفي حاله ال segmentationوال processهنقسمها لحاجه اسمها segments
او ممكن نقسمها pagesوهنعرف دلوقت الفرق بينهم مع مالحظه ان كل segmentاو
pageبرضه بتشاور علي frameاو segmentمعين في الذاكره بتعتنا
segment page
The process is divided into variable The process is divided into fixed
sized blocks sized blocks
اوعي تتلخبطوا بينها وبين ال contiguousاوعي تتلخبطوا بينها وبين ال contiguous
fixedاحنا قلنا ان هنا ال processبتنزل في dynamicاحنا قلنا ان هنا الprocess
بتنزل في اماكن متفرقه مش شرط تكون ورا اماكن متفرقه مش شرط تكون ورا بعض
بعض
تاني يا جماعه الفرق بين ال contiguousوال non contiguousالفرق الوحيد ان في
ال contiguousال processبتنزل حته واحده علي بعضيها سواء كانت الحته ديه مساحتها
ثابته او متغيره انما ال non contiguousال processبتنزل في حتت متفرقه سواء كانت
الحتت مساحتها ثابته او متغيره
Paging
Page number is an index for the frame number in the process page table
page table
طب حد يترجم بقي الهجص داه ... بسيط جد الموضوع...كل processبيبقي عندها page
tableودا بيبقي عباره عن arrayفيه كل pageبتشاور علي frameرقم كام في الذاكره
مثال كده
4 دا معناه ان ال pageرقم صفر بتشاور علي ال frameرقم 4وال pageرقم 0
6 بتشاور علي ال frameرقم 6وال pageرقم 0بتشاور علي frameرقم 00
00 وال pageرقم 3بتشاور علي ال frameرقم 011
011
Page table indicates corresponding frame to each page, such that the
]frame no can obtained through accessing pageTable[pageNo
هللا امال ايه بقي موضوع ال offsetداه بسيط جداااا...دلوقت احنا عرفنا هنروح علي انهي
frameطيب افرض انا مش عايز اكتب من اول ال frameافرض حجم ال 4 frameبايت
وانا عايز اكتب بايت واحد من اخر الفرم خالص بقوله مثال امشي 3بايتس من الفريم رقم كذا
وادي مثال
طيب نركز بقي هنقول دلوقت هوا عايز يكتب في
العنوان ال logicalداه > <0,2الحرف cهيترجمها
ازاي؟؟؟
Segmentation
هاه نفتكر بقي كان ايه البتاع داه؟؟ ال processبتقسسم لكذا قطاع متغير الحجم او variable
sized partitions/segments
طيب يبقي اكيد يعني لو هكتب حاجه الزم ابقي عارف هكتب من اول فين وكمان اخري فين
عشان ما يحلصلش ايرور
وبرضه هنا ال segment noبيقبقي ال indexبتاع الحاجه هللا نقولها دلقت
وبيبقي جواه حاجتين مش حاجه واحده اول حاجه انا ال physical addressبتاع
ال segmentبيبدا من اول فين وكمان موجود الحجم بتاع ال segmentطيب مثال احسن
عشان نفهم
طيب هنقول مثال عايز اكتب الحاجه اللي جوا
segment 0كلها (يعني باعتبار ان offset
بيساوي صفر) جوا الذاكره هعمل ايه؟؟
يعني عايز اكتب حاجه من segment 3خالص هبص في الجدول ال 3 indexهيقولي اكتب
من اول 3200بس انا عايز اسيب 5بايتس اللي هما ال offsetخالص هسيب البايت رقم
3011والبايت 3010وهكذا وهبدا كتابه من اول البايت رقم 3015
(تحذيييير ما حدش يذاكر الحمايه اللي في الكتاب في pagingالن الدكتور ما شرحتهاش
ومش موجوده في الساليدز النها هتتعارض مع حاجه في شبتر ) 9
ازاي بقي بسيط جدا انا بشوف الزم يكون offsetبتاعي اصغر من الحجم بتاع الsegment
اللي هوا limit register
Chapter 8
السالم عليكم
هنكمل مع ال OSودي الوقت وصلنا لل Main memoryهنتكلم عليها بتفصيل أكتر وهنشوةف ازاي هنستغل مساحه الميوري دي
بأفضل شكل ممكن وازاي هنحط البروسيس والداتا جواها بحيث نوفر الستوريج والبيرفورمانس ,وده ه returnعلى السيستم كلو ..
وزي ما احنا عارفين أن الميموري والريجسترز هما الوحيدين اللي ال CPUهتتعامل معاهم وهناخد منهم data
واحنا هنهتم بالميموري ,وطبعا الميموري بتتألف من , wordsوكل ورد من دول ليها addressوركزو بحته ال addressدي
عشان هنشتغل بيها بكل الشابتر ,عشان احنا واحنا منعمل البروغرام مش هيكون عندنا accessعلى ال addressبتاع الميموري
عشان السيكيورتي وحاجات تانيه ,سو احنا هنعمل addressلوجيكال وال Cpuهتحولو لل addressبتاع الميموري ,زي مثال
ال pointerاحنا لما منشاور على داتا بالميموري بالبوينتر ده منكون منشاور ب ,Logical Addressوال CPUهتحولو
لل physical Addressوالحته دي اسمها ال .... Binding
طب أنا محتاج أعرف ال Addressوالرغي اللي فات ده ليه اصال !!!
زي ما احنا عارفين أن ال Cpuمش بتشتغل taskوحده وخالص أل ,هيهة بتشتغل أكتر من تاسك بنفس الوقت ,ولما انا يكون عندي
أكتر من بروغرام عايز انفذهم مع بعض يبقا الزم اعملهم loadعلى الميموري عشان ال CPUهتشتغل عليهم ,يبقا أول حاجه لما انقل
البروغرام على الميموري هيبقا اسمو ,processطب ممكن انا عايز اشتغل على 100بروسيس وكل بروسيس بتاخد sizeمعين
بالميموري وكل بروسيس ليها sizeمختلف والميوموري مش بتقدر تشيلهم مع بعض احيانا يبقا انا الزم اشيل بروسيس واحط بروسيس
بالميموري ,وعشان اعمل الحاجه دي الزم اعرف كل بروسيس مكانها فين في الميموري وفين األماكن الفاضيه والمليانه ,وعشان كده
انا محتاج ال , Addressومادام احنا تكلمنا عن أن هنشيل ونحط بروسيس يبقى العمليه دي محتاجه مانجمنت للميموري عشان اعرف
فين األماكن الفاضيه وفين األماكن المليانه ببروسيس ,وكده هنالقي أكتر من طريقه عشان نحط البروسيس في الميموري ,عشان نوفر
اسرع وقت واقل ستورج ممكن .........................
الكالم اللي فات ده كلو عباره عن introductionعن الشابتر كلو ودي الوقت هنشرح كل كلمه وكل ساليد لوحده إن شاء هللا عز وجل
Background:
زي ما قولنا ان البرنامج منجيبو من الهارد ديسك ,ومنعملو loadعلى الميموري وبيبقى اسمو processعشان ال CPUتقدر تنفذ
ال instructionsبتاع البروسيس دي ...
Basic Hardware:
احنا عندنا أن كل ريجستر بيقراه ال CPUبسايكل وحده ,يعني هوة سريع جدا ان ال cpuمش هتاخد غير سايكل وحده عشان تقرأه
بينما الميموري هتاخد وقت أكبر بكتيير عشان كده أنا مضطر اني اعمل ميموري بين الريجستر والميموري واللي هيه الكاش ,وبعتقد
OS-Chap8 Summary
Dynamic Loading:
اتفقنا أن البروغرام هنقسمو ل subprogramإذا كان كبيير وكل subprogramلما ننقلو للميموري هيكون بروسيس ,أحيانا هيكون
البروغرام كبيير اوي علشان نحطو كلو في الميموري فاحنا هنا ,هنحط في الميموري البروسيس اللي عايزين ننفذها دي الوقت ,ولما
نعوز بروسيس جديدة هنعمل loadالبروسيس دي من الهارد ديسك للميموري ,ودا بقا اسمو Dynamic Loading
وأنا كده اللي مش هعوزو من البروغرام مش هحطو في الميموري ,وده هيوفرلي في الميموري وفي البيرفورمانس ..
Dynamic Linking:
ده بقا شبه dynamic loadingبس مع ال librariesبتاع البروغرام ,أزاي بقا ؟؟؟
أحنا عارفين ان البروغرام لما منعملو compilationبيقوم بيعمل linkلكل ال librariesاللي هيستخدمها ممكن تشوف الكتاب في
البيج 333الرسمه ...
فده اسمو static linkأنا مش مضطر اعمل لينك لكل ال librariesاللي مش محتاجها ده الوقت في بروسيس اللي شغال عليها ,فانا
هعمل كود صغير اسمو stubهوة هينفذ نفسه وبعد كده هيعمل replaceلنفسه مع Addressبتاع ال library routine
فانا هنا محتاج أن ال OSيتدخل عشان يتأكد ان ال routineده لسا ضمن البروسيس بتاعتي عشان السيكيورتي ...
وده اسمو Dynamic linking
والسيستم اللي بتعمل الحاجات ده اسمها بقا Shared libraries
Swapping:
الجزء ده بيتكلم عن البروسيس اللي هشيلها من الميموري لما عوز اشيلها ...
فانا هشيلها وحطها في مكان بالهارد ديسك اسمو Backing storحتى ارجعها تاني للميموري وكمل تنفيذها لو لسا أدامها تنفيذ ..
وال Backing storeأقدر أأكسس عليه بسرعه ويكون كبييير بحيث أقدر اخزن فيه كل البروسيس اللي في الميموري لكل اليوزرس
اللي في السيستم ..
طيب أنا هشيل اني بروسيس واحط اني بروسيس يبقى هنا عندنا حاجه اسمها roll out ,roll inلك بروسيس هيكون عندي priority
فانا هشيل ال low priority processوهحط مكانها high priority process
الجزء األكبر من الوقت اللي بياخدو ال swappingهو في ال transfer timeللهارد ديسك ,فحجم البروسيس بيلعب الدور في
زمن ال ... swapping
Contiguous Allocation:
ودي بكل بساطه بتقول ان أنا مقسم المين ميموري لقسمين األول لل OSوالتاني لليوزر بروسيسز ,بحط ال OSفي ال low
memoryوالبروسيسز high memory
وبقسم كل اليوزر بروسيسز ميموري ل holesكل holeبحط فيها بروسيس ,وال osبيعرف فين ال holesالفاضيه وفين المليانه
..
احنا بقا عندنا holesفاضيه اول ما ال OSيبتدي ,وبعديها أنا بحط فيها بروسيس وبخلص بروسيس ,بشيل بروسيس وبحط بروسيس
,والدنيا هتبقى مش مترتبة ,يعني هالقي holeفاضيه وبعديها مليانه وبعديها فاضيه ,وكل وحده منه ب Sizeمختلف عن التانيه ,
طب أزاي أنا بحط بروسيس وسط الزحمه دي بيقلك انا عندي تالت طرق :
First-fit and best-fit better than worst-fit in terms of speed and storage utilization.
Fragmentation:
يعني يكون عندي مكان في الذاكره مش مستفيد منه وبعديه في اماكن فيها بروسيس مستفيد منها ,يعني األماكن الفاضيه مش متجاوره مع
بعضها ,عندنا نوعين:
: External
وده يعني أن المساحه الفاضيه بقدر احط فيها بروسيس ,بس كل المساحات الفاضيه في الميموري مش متجاورة مع بعضها ,
: Internal
وده يعني أن يكون عندي مساحه فاضيه بس ما بتوسعش بروسيس وهيه مساحه نتيجه أني حطيت بروسيس في مكان بروسيس أكبر منها
بسنه وزاد عندي مساحه صغيره مثال :
أنا عندي مساحه فاضيه في الميموري بعد ما شلت بروسيس ,والمساحه دي مثال 14,364بايت ,عندي بروسيس عايز احطها في
المكان ده والبروسيس دي حجمها 14,362بايت يبقى الفرق ما بين المكان الفاضي وحجم البروسيس هوة 2بايت والمساحه دي مش
هقدر احط فيها بروسيس عشان هية صغيره جدا وأنا مش مستفيد منها تبقى دي مشكله واسمه internal fragmentation
Paging:
دي طريقه جديده هحط بيها البروسيسز بالميموري ,هبدأ هيكون عندي تصوريين للميموري ,األول هوة logicalبعقلي والتاني هوة
physicalالحقيقي ,لما يكون معايا البروسيس هقسم الميموري ل pagesكل pageليها sizeثابت وهيكون تقريبا 512بات لحد
8,192بايت ,يبقى هحط البروسيس ضمن البيجز فمثال هيكون عندي بروسيس حجمها 4كيلو بايت والبيج سايز عندي 512بايت
فالبروسيس هتتخزن في 4كيلو\ 512هيبقوا , pages 8وهروح للميموري هقسمها ل framesكل فريم ليها نفس ساز البيج نفسها ,
ييبقى انا هنا محتاج برضو frames 8عشان اخزن البروسيس دي ,طب انا هعرف كل بيج في اني frame؟؟؟
أول حاجه أنا كيوزر مش هعرف اي حاجه عن الفريم :Dعشان دي مهمه ال , OSبس هوة بيعمل tableبيعمل جواه mappingما
بين كل pageوكل .. frame
OS-Chap8 Summary
في الطريقه السابقه بتاعت reallocationكان عندنا اتنين ) registers (base,limitعشان أعرف كل بروسيس فين ,دي الوقت أنا
محتاج .. logical Address
هخزنها في أني فريم ,وهاخد 12الباقيين ودول هيكونو ال offsetودول هيقلولي ضمن البيج ده او الفريم ال wordاللي رقمها 12انا
عايزها ...
Paging Hardware
غالبا بيكون التعامل مع البيج والتحويل ده ,عن طريق الهارد وير وبيكون في حته هارد وير هي اللي بتعمل mappingمع البيج تيبل
وبتدي ال physical address
OS-Chap8 Summary
في page methodأنا هيكون عندي أن البروسيس مش هتتخزن في المميموري كلها جنب بعض ممكن 5بيج منها تتخزن في اول
الميموري و 3بيج في النص و 4بيج في األخر وبينهم في بيجز لبروسيسز تانيه طالما أنا عندي ال page tableلكل بروسيس فانا
هقدر أأكسس كل بروسيس واعرف اجيبها
زي ما قلنا ان ال accessعلى البيج تيبل هيكون عن طريق حته هارد وير مخصصه ليه ,وال page tableهيكون موجود في
الميموري ,يبقى عشان أوصلو هعمل registerاسمو page-table-base-registerوهحط بيه االدرس بتاع البيج تيبل في الميموري
,هعمل ريجستر تاني اسمو page-table length registerهحط بيه سايز بتاع التيبل ,نفس الفكره بتاعت البيز والليمت ريجستر !!!
طب دي الوقت عشان اوصل ألي بيج في البيج تيبل ده محتاج الرقم بتاع البيج ,طب لو أنا عندي سايز البيج تيبل كبيير وغالبا بيكون
كبيير مثال مليون بيج جواه وكل بيج برضو فيها انستركشنز كتيير ,يبقى عشان اوصل ل instructionمعينه في بيج معينه الزم ادور
عالى البيج في المليون بيج وبعديها جواها على األنستركشن دي ,وكده هياخد مني وقت ياما ,لذلك هما عملو زي الكاش ميموري
وعملو تيبل صغير فوق التيبل الكبيير اسمو:
لما أجي ومعايا بيج عايز أجيب الفريم بتاعتها ,أول حاجه هبص على ال TLBلو لقيتها جواه ,هخد الفريم وأكمل اكسس على الميموري
,لو مش جواه دي اسمها TLB missهروح وادور على البيج في البيج تيبل الكبير وامري هلل :Dوأكسس على الميموري بعد ما اعرف
رقم الفريم وارج واقوم واخد البيج والفريم واحطهم في ال TLBلو في مكان هحطهم بيه لو أل هقول لل OSيفضيلي مكان ,وهوة بقا
هيشوف هيعمل swapمع مين حسب ال policeمعينه ...
OS-Chap8 Summary
أنا عايز اعرف hit ratioواللي هية النسبه اللي هالقي البيج فيها في ال LTBوهرمزلها ب α
القانون ده بتاع الدكتور أنا هشرحوا هوة شرحو موجود في الكتاب في بيج .. 348
اوال أنا عندي حالتين األولى اني أنا لقيت البيج في ال TLBفهيكون الزمن عندي هوة األكسس على ال LTBوالزمن لحتى أكسس
الميموري ,تانيا لما مش هالقي البيج في ال LTBفهيكون الزمن في السيرش في ال LTBوالزمن في السيرش في البيج تيبل +الزمن
في األكسس الميموري ,القانون ضرب كل حاله بالريشوي بتاعتها وجمعهم لبعض وكده هيطلع ال Effective access time
Memory Protection:
من اسمها يعني هية مسؤووله عن الحمايه وكده ,يعني ازاي أنا اقدر احافظ على الميموري من أني كل ما استخدم بيج وأجيب فريم ,
مش هجيب الفريم الغلط أو أكتب فوق فريم غلط ,يعني هوة هيحددلي مساحه في الميموري أمشي عليها وكل بيج مش هتتعدى على بيج
تانيه وكل فريم برضو ,طب ازاي بيعمل كده !!؟؟:
أوال هيحط لكل بيج بت زياده ,هيحدد من خالله ان البيج ده أو الفريم المقابله ليها هيه read-onlyوال read-write
حاجه اهم هيحط لكل بيج برضو بت زياده هيحدد من خالله أن البيج ده validليا وال invalidوالبت ده اسمو Valid-Invalid bit
أحنا اتفقنا أن الميموري هتكون اسمين ,قسم لل OSواألقسم الباقي , user’s processesفالبيج اللي مسموح ليا أني استخدمها هيكون
البت ده Validوغير كده هيكون Invalidزي المثاال ده :
البيج 6و 7انا مش مسموح أني استخدمهم ,عشان كده ادامهم invalid
OS-Chap8 Summary
Shared Pages:
بعد ما اتفقنا أن هنعمل الميموري بيجز وفريمز ,لقينا أن ممكن نستفيد من التكنولوجي دي أن أحنا ممكن بالطريقه دي نخلي البروسيس
اللي بتنفذ كود مشترك تنفذ نفس الكود بزمن واحد يعني نعمل Shareللكود ,عمليا أحنا منعمل شير للبيجز بس الزم يكون في شروط ,
أوال الكود ده الزم يكون reentrantيعني read onlyما ينفعش أني اغير بيه والبروسيس بتستخدمه ,مثال :
لو عندي سيستم بيخدم 40يوزرس وال 40دول كلهم بيستخدمو editorحجمو 150كيلو وكل واحد منهم بيشتغل على داتا حجمها 50
كيلو ,يبقى أنا محتاج ( 40*)50+150يعني 8000كيلو بايت في الميموري ,طيب ليه أنا ما خلي الكود بتاع ال editorثابت في
الميموري وكل بروسيس هتستخدمو عالداتا بتاعتها ,يعني أنا محتاج editorواحد بس يعني هحتاج 50*40+150هيبقة 2150كيلو
بايت بس ...الصورة في السلاليد 33بتوضح الكالم ده على مثال صغير تالته بروسيسز ...
مافيش حاجه جديده زي ما قلت قبل شوي هقسم التيبل لغروبس وحطهم في بيج تاني ,يبقى أنا كده عملت اتنين بيج ,يعني tow-level
,الساليد .. 36
طيب دي الوقت هاوصل للبيج ازاي ؟؟!!
هاخد ال logical addressاللي هوة 32بت واقسمو لقسمين :
:virtual page number -1ده عشان اتأكد أن البيج ده اللي انا عاوزها
: value of the mapped page frame -2ده عشان اخد الفريم منها واروح أأكسس في الميموري
فأنا هعمل هاش للبيج نمبر وهاخد اول elementباليست اشوف البيج نمبر هوة نفس للبيج اللي معايا لو هوة هاخد
value of the mapped page frameواروح أأكسس الميموري ,لو مش هوة هشوف البوينتر واروح لل next element
واعمل معاه نفس الحكايه لحد ما القي البيج بتاعتي ..
OS-Chap8 Summary
Segmentation:
دي بقا هقسم البرنامج بتاعي لعده اقسام مثال :
main program,
procedure, function,
method, object,
local variables, global variables,
common block, stack,
symbol table, arrays
كل قسم هسميه segmentوهعمل تيبل فيه كل سيغمنت موجوده فين في الميموري ,وكل entryفي التيبل فيه
ولو حصل أن السيغمنت نمبر اللي انا عملتو أكبر من عدد السيغمنت اللي عندي ال OSهيطلع trap
ودي مشروحه كويس في الكتاب في بيج …. 356
Chapter Eight OS
Memory Management
Program must be brought into memory and placed within a process for it to be run.
User programs go through several steps before being Run
Job queue:-collection of processes on the disk that are waiting to be to run
You can never have enough memory to hold the OS and all the processes
need to transfer blocks between secondary and main memory as needed
Memory organization
Part reserved for OS
Rest is divided among processes
Try to put as many processes in memory as possible, to keep the CPU busy
Memory management objective:
To pack as many processes into memory as possible, needs to be allocated efficiently
Requirements for Memory Management to satisfy:
Relocation – Protection – Sharing - Physical Organization
Relocation
Programmers dont know where will the program be placed in the memory
While the program is being executed it may be swapped to the disk and turned back
to the main memory in different location
Restriction:- But its address saved in the CPU so when its changed CPU will have
difficulty in executing the program
Relocation:- ability to swap a program from disk into any location in memory
Memory references must be translated in the code to actual physical memory address
Protection
Prevent processes from interfering with the OS. or other processes cant refrence at
any process without permisiion
Protect process from accidental or intentional interference:
Can't know all memory references in advance anyway (arrays, data structures)
Must check at run time (when mapping is done) and therefore when operating system
is not active "handled by hardware"
Sharing
Allow several processes to access the same portion of memory (access control)
Processes executing same program
Sharing data structure i e producer/consumer
Physical Organization
Allocation of physical memory
Moving data between secondary and main memory
Memory management is the responsibility of the OS and not the programmer
programmer doesn’t know how much space will be available
OS can make it transparent to user, simplify programmer's job
Swapping
A process can be swapped temporarily out of memory to a backing store, and then
brought back into memory for continued execution
Backing store– fast disk and large to accommodate copies of all memory images
for all users; must provide direct access to these memory images
Roll out, roll in:- Swapping based on proirity lower proiority process swapped out
so higher can be loaded
transfer time; total transfer time is directly proportional to the amount of memory
swapped// i think when process swaped to the disk her priority increasing so that it
could go back to the memory and the lower amount of memory the higher its priority
increased the lower transfer time "thats my thoght"
The criteria for decisions regarding swapping
Fairness: processes take alot of CPU usage swapped out to give the others a chance
Creating a good job mix:
jobs that compete with each other will be swapped out more than jobs that
complement each other.
For example, if there are two CPU-bound jobs and one I/O-bound job, it makes sense
to swap out the CPU-bound jobs alternately, and leave the I/O-bound job memory
resident.
Logical vs. Physical Address Space
Logical address: generated by the CPU; also referred to as virtual address
Physical address: – address seen by the memory unit
Memory Management Unit (MMU)
Hardware device that maps virtual to physical address
In MMU scheme, the value in the relocation register is added to every address
generated by a user process at the time it is sent tomemory
The user program deals with Logical addresses; it never sees the physical addresses
Memory Allocation Mechanisms
Contiguous Allocation
Paging
Segmentation
Contiguous Allocation
Main memory usually into two partitions:
Resident operating system, usually held in low memory with interrupt vector
Rest of memory is left for programs
Establish programs partition once at system initialization
Relocation-register scheme used to protect user processes from each other, and from
changing operating-system code and data
Relocation register contains value of smallest physical address; limit register contains
range of logical addresses – each logical address must be less than the limit register
Registers Used during Execution
Base register:-Starting address for the process
Limit register:-Ending location of the process
These values are set when the process is loaded or when the process is swapped in
The value of the base register is added to a relative address to produce an absolute
address
The resulting address is compared with the value in the bounds register
If the address is not within limits, an interrupt is generated to the operating system
Memory Partitioning
Fixed (Equal-Sized) Partitions:-Any process whose size is less than or equal to
the partition size can be loaded into an available partition
If all partitions full, and no process ready, then swap in a new process (remove one)
Limits size of a process
Inefficient use of memory for small processes ( internal fragmentation)
Dynamic (Variable-Sized) Partitions:-Partitions are of variable length and
number
Handle larger programs with larger partitions
Each program allocated exactly as much memory as it requires
Eventually holes appear in main memory between the partitions
We call this "External Fragmentation"
Dynamic Partitions
Hole:– block of available memory; holes of various size are scattered in memory
When a process arrives, it is allocated for a hole large enough to accommodate it
a) allocated partitions b) free partitions (hole)
Dynamic Storage Allocation Problem
Operating system must decide which free block to allocate to a process
How to satisfy a request of size N from a list of free holes
First-fit: Allocate the First hole that is big enough
Best-fit: Allocate the Smallest hole that is big enough;
must search entire list, unless ordered by size. Produces the smallest leftover hole.
Worst-fit: Allocate the Largest hole; must also search entire list Produces the
largest leftover hole
First-fit and best-fit better than worst-fit in terms of speed and
Fragmentation
External Fragmintation:-free memory spaces but not contiguous
Internal Fragmintation:-Free memory spaces may be larger than the requested
size
Reduce external fragmentation by compaction
Shuffle memory contents to place all free memory together in one large block
Compaction is possible Only if relocation is dynamic, and is done at execution time
I/O problem // the problems of I/O
Latch job in memory while it is involved in I/O //close on the job // i thing when I/O
needed the job should be swapped to CPU
Do I/O only into OS buffers
Paging
Support Needed for Virtual Memory
Hardware must support paging and/or segmentation
Operating system must manage the movement of pages and/or segments between
secondary memory and main memory
Logical address space of a process can be noncontiguous;process is allocated physical
memory whenever the latter is available
Divide physical memory into fixed-sized blocks called frames (size is power of 2,
between 512 bytes and 8192 bytes)
Divide logical memory into blocks of same size called pages Keep track of all free
frames
Operating system maintains a page table for each process contains the frame location
for each page in the process
To run a program of size N pages, need to find N free frames and load program
Set up a page table to translate logical to physical addresses memory address consist
of a page number and offset within the page
// i think pages is always equal or smaller than frames also page is part of frames and
the process is devided into pages and these pages spread over frames and not always
contiguous
Address Translation Scheme in Paging
Address generated by CPU is divided into:
Page number(p)–an index contains base address of each page in physical memory
Page offset (d)– with base address defineing the physical memory address
I think it means that logical adress consist of two parts first the Pnumber and thats an
index in the page table refers to adress of the page in the physical memory the other
part is Poffset and this is part of the physical address without changing
Page Size
Small page size
less internal fragmentation// if it means more external so its bad otherwise is good
larger page table
more pages in main memory
reduce page faults since pages contain recent references//good
Large page size
more internal fragmentation//if it means less external so its good otherwise is bad
smaller page table
secondary memory is designed to efficiently transfer large blocks of data //good
increase page faults since unreferenced data in memory
Shared Pages
Shared code
One copy of read-only (reentrant) code shared among processes (i.e., text editors,
compilers, window systems).
It must appear in same location in the logical address space of all processes
Private code and data
Each process keeps a separate copy of the code and data
The pages for the private code and data can appear anywhere in the logical address
space // look at page 39.
Segmentation
Let programmer view memory as a number of dynamically-sized partitions A
program is a collection of segments. A segment is a logical unit such as: main
program, procedure, function, method, object,local variables, global variables
There is a maximum segment length
Addressing consist of two parts –a segment number and an offset
Since segments are not equal, segmentation is similar to dynamic partitioning
Advantages
independent linking/loading of modules
sharing
Protection
// i think its more familiar to pages only changed the name and its dynamical not
fixed like frams or static like pages :D
Segmentation Architecture
Logical address consists of a two tuple: <segment-number, offset>,
Segment table:-maps two dimensional physical addresses; each
table entry has:
base – contains the starting physical address where the segments reside in memory
limit– specifies the length of the segment
Segment-table base register (STBR) points to the segment table’s location in memory
Segment-table length register (STLR) indicates number of segments used by a
program;
Relocation:-Dynamic by segment table
Sharing:-shared segments, same segment number
Allocation:-first fit/best fit, external fragmentation
Protection:-With each entry in segment table associate:
validation bit = 0 illegal segment
read/write/execute privileges
Protection bits associated with segments; code sharing occurs at segment level
Since segments vary in length, memory allocation is a dynamic storage-allocation
problem
A segmentation example is shown in the following diagram .
Operating systems
Chapter 9: Virtual Memory Management
OsatazOnline
http://www.facebook.com/Ostaz.Online
عن أبي هريرة -رضي اهلل عنه -ق ال :ق ال رسول اهلل -صلى اهلل عليه وسلم
) -:المؤمن القوي خير وأحب إلى اهلل من المؤمن الضعيف ،وفي كل
خير ،احرص على ما ينفعك ،واستعن باهلل وال تعجز(
صدق رسول اهلل –صلي اهلل عليه وسلم-
Ch. 9: Virtual Memory Management
مقدمه
Only required pages are loaded to the program, if a page does not exist
in the main memory, it's loaded to a memory frame, if not, then we
need to swap out a process to provide a free frame in memory
ان البرنامج بيتقسمCh. 8 منpaging يعني بستخدم مفهوم ال نفس الكالم بيكرر نفسه
البرنامج عايزها وبعملpage اليswapping in وهزود عليه حته كمان اني بعملpagesل
معينه هخرجها بناء علي طرق معينه هنشوفها في اخر الشبترpage لswapping out
ديه موجوده وال ال فيpageهوا البرنامج هيعرف منين ال... طيب بقي فيه حاجه مهمه
logical ان البرنامج بيبقي شايف ال8 غلطططططططط احنا قلنا في شبتر... memoryال
هيا الليMMUانما ال... وداه بيبقي جواه البرنامج كله متحمل تخيلياaddress space
validation وكمان بقي الlogical address mappingبتعمل عمليه ال
Value 0: the page is either invalid (not in the logical address space) or
valid but it is not in the memory
صفحه معينه افرض الصفحه ديه مشMMUطيب تماااااام دلوقت بقي البرنامج طلب من ال
page fault هنا بقي تحصل حاجه اسمهاmemoryموجوده في ال
Page fault: a situation in which the required page is not residing in the
main memory
1- Check an internal table at the process to know whether the page has
invalid address or it is just not in the memory
If the page has an invalid address -> Interrupt OS with addressing error
Else
5-restart the instruction that was stopped because it didn't find the page
Finding a free frame 2 طيب باقي الشبتر كله بقي هوا شرح للخطوه رقم
وكده اشطه الكالم داه فل الفلfree frame دلوقتي انا ادامي حالتين يا اما يكون فعال في
swapping خلصت علي كده خالص هنعملmemory او ان تكون الpageونحط جواح ال
ديه بقي بيبقي فيها كذا خطوهswappingونطلع واحده برا عشان ندخل المطلوبه حركه ال
page replacement ادرجناهم تحت اسم
)Page replacement: swapping out a page from the memory (victim page
after writing it to a backing store (hard disk), then the required page can
be swapped in to the memory
طيب ممكن نضيف تحسين للموضوع داه بدل ما كل شويه اكتب الصفحه اللي هخرجها من
ال memoryعلي ال hardوممكن تكون الصفحه ما اتعدلتش خالص انا هستخدم حاجه
اسمها modify/dirty bitوديه بتقولي ال pageاتغيرت وال ال ...لو اتغيرت امري هلل
هكتبها علي ال hard diskلو ما اتغيرتش خالص الحياه فله ومش هحتاج اكتبها
نخش بقي علي الجزء اللي الناس بتسن سنانها من الصبح عليه بس االول قوم ذاكر اللي فات
داه من الساليدز بتاعه الدكتور يال
)(FIFO-Optimal-LRU
الراجل الحلو داه بيقولك لو انت محتاج مكان فاضي خرج ال pagesبالترتيب يعني لو 1دخلت
وبعدين 2هنخرج واحد االول وبعدين هنخرج 2واوعي تنسي ان لو في pageموجوده جوا
ال main memoryفانا مش هحتاج اني اخرج حاجه النها اصال موجوده
ملحوظه :دا يعتبر من اسوا خوازمات االستبدال النه بيزود ال page faultsطيب نخش
علمثال بقي
جتلنا ال -2مش موجوده ومفيش مكان فاضي – خالص طلع حاجه – هطلع اول واحده دخلت
اللي هيا 7
وهكذا بقي
2-Optimal
داه بقي بيعمل احسن performanceالنه بيقلل ال page faultsبس ما تفرحش اوي كده
النه اصال ما ينفعش يتنفذ زي ما بيقولو كده infeasibleالنه بيحتاج انه يعرف ايه كل
الصفحات اللي هتتطلب بعد كده في المستقبل وطبعا داه مستحيل فبيتم استخدامه للبحث العلمي
مش اكتر
Swap out the process that will not be required for the longest time
يعني بشوف انهي واحده هييجي عليها الدور في االخر اني اطلبها وهيا ديه اللي هطلعها ...ايه
الكالم داه انا مش فاهم حاجه ...هقولك بمثال
لو مثال دلوقت ال memoryجواها 1و 2و 3وانا عايز اطلع واحده فيهم و هفترض ان ديه
الصفحات اللي هتتطلب مني
987987657311123123
ركز بقي قلنا ن المموري جواها 1و 2و 3دلوقتي انا محتاج اعرف ترتيب ظهورهم في
الصفحات المطلوبه
هالقي ان 3اتطلبت وبعدين واحد اتطلبت وبعدين 2اتطلبت يعني اخر واحده هتتطلب هيا رقم
2يبقي رقم 2اللي هتطلع
اوعي بقي تقع في الفخ انك تكمل لالخر يعني ايه...يعني بعد ما يجيلك كل واحد ظهرت امتي
خالص اقف ما تكملش لالخر وتقولي ال دا 3هيا اخر واحده هتتطلب ال انت اول ما تالقي ال3
ظهروا هتقف علي طول وتشوف انهي اخر واحده فيهم وتطلعها برا وادي مثال المحاضره
20304230321201701
اخر واحده هتتطلب هيا ال 7يبقي هتطلع ال 7وادخل بدلها االتنين
دلوقت جت – 3مش موجوده ومفيش مكان برضه هدور مين هيطلع من ال memory
304230321201701
اه تمام ال 1اخر واحده هتتطلب يبقي هنطلع الواحد ونحط بدلها ال3
دلوقت جت – 4مش موجوده – نفس الحوار بقي هنشوف مين اخر واحده هتيجي من اللي
جوا ال memoryدلوقت عشان اطلعها
4230321201701
وهكذا بقي
لو فهمت داه كويس كده تمام انت فهمت الجاي كمان
3-LRU (Least recently used): swap out the process that has not been
required for a long time
هيا هيا هيا هيا هيا optimalبس بدل ما هبص الدام هبص لورا الني ببقي مش عارف ايه
اللي جاي لكن اكيد عارف ايه اللي اتطلب
3332318973
هنالقي ان رقم 2هيا اخر واحده اتطلبت ( هناك في optimalكنا بندور علي اخر واحده
هتتطلب هنا بندور علي اخر واحده اتطلبت)
طيب بقي ناقص حته بسيطه جدا ان الخوازم داه فيه حبه over head
عشان طبعا الزم تعرف كل pageامتي اخر مره اتطلبت ودا بطريقتين
يعني مع كل pageهحط الوقت اللي هيا اتطلبت فيه اخر مره وككده هزود عندي مساحه
الprocess
يعني هحهط في stackوبالتالي هعرف مين اللي بقالها مده ما اتطليتش بس طبعا هنا هضيع
وقت عشان ادور في الstack
Chapter Nine OS