Core Foundations: OS Architecture الأسس الجوهرية: بنية نظام التشغيل
What happens when you press the power button? Understanding the Kernel, System Calls, and the Dual-Mode Operation. ماذا يحدث عند الضغط على زر التشغيل؟ فهم الـ Kernel، و System Calls، و Dual-Mode Operation.
What is an Operating System? ما هو نظام التشغيل؟
An OS is a program that acts as an Intermediary between the user and the hardware. نظام التشغيل هو برنامج يعمل كـ وسيط (Intermediary) بين المستخدم والأجهزة (Hardware).
Main Goals الأهداف الرئيسية
- Convenience:Convenience (الراحة): Makes the computer easier to use (Abstraction). Turns "ugly hardware" into beautiful interfaces. يجعل الحاسوب أسهل في الاستخدام (التجريد). يحول "الأجهزة المعقدة" إلى واجهات جميلة.
- Efficiency:Efficiency (الكفاءة): Manages resources (CPU, Memory, Disk) optimally. يدير الموارد (CPU، الذاكرة، القرص) بشكل مثالي.
- Protection:Protection (الحماية): Ensures security and reliability. يضمن الأمن والموثوقية.
Key Definitions تعريفات رئيسية
- Kernel:Kernel (النواة): The one program running at all times. The core of the OS. البرنامج الوحيد الذي يعمل طوال الوقت. هو جوهر نظام التشغيل.
- System Programs:System Programs: Ships with the OS but not part of the kernel (e.g., File Manager). تأتي مع نظام التشغيل ولكنها ليست جزءاً من الـ Kernel (مثل مدير الملفات).
- Application Programs:Application Programs: User software (e.g., Chrome, Word). Not part of the OS. برامج المستخدم (مثل Chrome, Word). ليست جزءاً من نظام التشغيل.
System Architecture بنية النظام (System Architecture)
The Bootstrap Program The Bootstrap Program
The first code executed on power-up. أول كود يتم تنفيذه عند التشغيل.
- Stored in ROM or EEPROM (Firmware). يخزن في ROM أو EEPROM (برنامج ثابت Firmware).
- Initializes all hardware (CPU, Memory, Controllers). يهيئ جميع الأجهزة (CPU، الذاكرة، وحدات التحكم).
- Loads the OS Kernel into memory and starts execution. يحمل OS Kernel إلى الذاكرة ويبدأ التنفيذ.
Interrupts Interrupts (المقاطعات)
The mechanism for Hardware/Software to signal the CPU. آلية للأجهزة/البرمجيات لإرسال إشارة إلى الـ CPU.
- Hardware Interrupt:Hardware Interrupt: Signal from device (e.g., Key press, Disk ready). إشارة من جهاز (مثل ضغط مفتاح، القرص جاهز).
- Software Interrupt (Trap/Exception):Software Interrupt (Trap): Signal from software (e.g., Error, System Call request). إشارة من برنامج (مثل خطأ، طلب System Call).
- Handling:المعالجة (Handling): CPU stops, saves state, jumps to Interrupt Service Routine (ISR). يتوقف الـ CPU، يحفظ الحالة، ويقفز إلى Interrupt Service Routine (ISR).
I/O Operation Structure هيكل عملية الإدخال/الإخراج (I/O)
Architecture Types أنواع البنية
Multiprocessor Systems (Parallel) Multiprocessor Systems (Parallel)
Systems with 2 or more processors in close communication, sharing the computer bus, clock, memory, and peripherals. أنظمة تحتوي على معالجين أو أكثر في اتصال وثيق، تتشارك في الناقل، الساعة، الذاكرة، والأجهزة الطرفية.
Clustered Systems Clustered Systems
Multiple individual systems (nodes) gathered together. Usually share storage via a Storage Area Network (SAN).
High Availability: If one node fails, another takes over.
أنظمة فردية متعددة (nodes) مجمعة معاً. عادة ما تشترك في التخزين عبر شبكة تخزين (SAN).
High Availability: إذا فشلت عقدة واحدة، تتولى أخرى المهمة.
OS Operations عمليات نظام التشغيل
Dual-Mode Operation Dual-Mode Operation
Critical Concept مفهوم جوهريTo protect the OS from user errors, hardware provides two modes: لحماية نظام التشغيل من أخطاء المستخدم، توفر الأجهزة وضعين:
Restricted access. Cannot execute privileged instructions (e.g., halting CPU, accessing I/O directly). وصول مقيد. لا يمكن تنفيذ تعليمات ذات امتيازات (مثل إيقاف CPU، الوصول المباشر لـ I/O).
Full access. Executes privileged instructions. Entered via System Calls or Interrupts. وصول كامل. ينفذ التعليمات ذات الامتيازات. يتم الدخول إليه عبر System Calls أو Interrupts.
System Calls System Calls
The programming interface to the services provided by the OS. Typically written in C/C++. واجهة البرمجة للخدمات التي يقدمها نظام التشغيل. تكتب عادة بـ C/C++.
// App needs to read a file...
1. User App calls open() -> Switches to Kernel Mode
2. OS executes sys_open() -> Hardware Access
3. OS returns file handle -> Switches back to User Mode
The Exam Vault خزنة الاختبار
Professor's Secrets & Trap Avoidance أسرار البروفيسور وتجنب الفخاخ
TRAP: System Call vs API فخ: System Call vs API
APIs (like `printf()` in C) are library functions running in User Mode.
System Calls (like `write()`) are the actual OS entry points running in Kernel Mode.
Most APIs eventually invoke System Calls, but they are not the same thing.
APIs (مثل `printf()` في C) هي دوال مكتبة تعمل في User Mode.
System Calls (مثل `write()`) هي نقاط الدخول الفعلية لنظام التشغيل وتعمل في Kernel Mode.
معظم APIs تستدعي System Calls في النهاية، لكنهما ليسا نفس الشيء.
TRAP: Mode Switching فخ: تبديل الوضع (Mode Switching)
The switch from User to Kernel mode happens via a Trap (Software Interrupt). It is hardware-triggered by a specific instruction. It is NOT just a simple function call jump. التبديل من User إلى Kernel mode يحدث عبر Trap (Software Interrupt). يتم تشغيله بواسطة الأجهزة عبر تعليمة محددة. إنه ليس مجرد قفزة استدعاء دالة بسيطة.
SECRET: The Timer سر: المؤقت (The Timer)
How does the OS prevent an infinite loop in a user program from freezing the whole system?
The Timer Interrupt. The hardware timer periodically interrupts the CPU, giving control back to the OS scheduler. This ensures the OS always regains control.
كيف يمنع نظام التشغيل حلقة لا نهائية في برنامج المستخدم من تجميد النظام بأكمله؟
The Timer Interrupt. يقوم مؤقت الأجهزة بمقاطعة الـ CPU بشكل دوري، ويعيد التحكم إلى مجدول نظام التشغيل. هذا يضمن أن نظام التشغيل يستعيد التحكم دائماً.
KEY CONCEPT: Virtualization مفهوم أساسي: Virtualization
Emulation runs code for a different CPU type (slow).
Virtualization runs code for the SAME CPU type but isolates it (fast).
The Hypervisor (VMM) sits between hardware and OS to manage VMs.
Emulation تشغل كوداً لنوع CPU مختلف (بطيء).
Virtualization تشغل كوداً لنفس نوع CPU ولكن تعزله (سريع).
يقع Hypervisor (VMM) بين الأجهزة ونظام التشغيل لإدارة الـ VMs.