Processesالعمليات
مقدمة الفصل
ماذا ستتعلم في هذا الفصل
- The notion of a process — a program in execution — and what it includes.
- Process states, the state diagram and the process control block (PCB).
- Process scheduling: scheduling queues, long-, short- and medium-term schedulers, context switch.
- Operations on processes: creation (fork, exec) and termination.
أقسام الفصل
- 1The process conceptمفهوم العملية
- 2Process states and the state diagramحالات العملية ومخططها
- 3Process control block (PCB)كتلة التحكم بالعملية
- 4Process scheduling queuesطوابير جدولة العمليات
- 5Schedulersالمجدولات
- 6Context switchتبديل السياق
- 7Process creationإنشاء العمليات
- 8Process terminationإنهاء العمليات
تلميح: استخدم أسهم لوحة المفاتيح للتنقل بين الشرائح.
What is a process?مفهوم العملية
The process concept
A program in execution; process execution must progress in sequential fashion.
A process includes
- Program counter
- Stack
- Data section
- Batch system — jobs; time-shared systems — user programs or tasks.
- The textbook uses the terms job and process almost interchangeably.
| Region | Note |
|---|---|
| stack |
|
| (free space) | between stack and heap |
| heap | grows up |
| data | |
| text | at address 0 |
Process statesحالات العملية
تذكّر معنى كل حالة قبل الكشف.
- new
The process is being created.
- running
Instructions are being executed.
- waiting
The process is waiting for some event to occur.
- ready
The process is waiting to be assigned to a processor.
- terminated
The process has finished execution.
Diagram of process stateمخطط الحالات
Process states and the state diagram
| Fromمن | Toإلى | Label on the diagram (slide 8)التسمية في المخطط |
|---|---|---|
| new | ready | admitted |
| ready | running | scheduler dispatch |
| running | ready | interrupt |
| running | waiting | I/O or event wait |
| waiting | ready | I/O or event completion |
| running | terminated | exit |
Process control block (PCB)كتلة التحكم PCB
The information associated with each process.
- 1Process state
- 2Program counter
- 3CPU registers
- 4CPU scheduling information
- 5Memory-management information
- 6Accounting information
- 7I/O status information
Process scheduling queuesطوابير الجدولة
Set of all processes in the system.
Set of all processes residing in main memory, ready and waiting to execute.
Set of processes waiting for an I/O device.
- Processes migrate among the various queues.
Long-term vs short-term schedulerالمجدولات
Schedulers
| Schedulerالمجدول | Selectsيختار | Invokedيُستدعى | Noteملاحظة |
|---|---|---|---|
| Long-term (job scheduler) | Which processes should be brought into the ready queue | Very infrequently (seconds, minutes) — may be slow | Controls the degree of multiprogramming |
| Short-term (CPU scheduler) | Which process should be executed next, and allocates CPU | Very frequently (milliseconds) — must be fast | لا تذكر الشرائح شيئًا هنا. |
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
Medium-term schedulingالجدولة متوسطة المدى
Schedulers
Slide 17 figure, in words
- 1
Processes enter the ready queue and run on the CPU; a process that waits for I/O goes to the I/O waiting queues and returns to the ready queue after I/O.
- 2
The medium-term scheduler can swap out a running process: it becomes one of the partially executed swapped-out processes.
- 3
Later it is swapped in back to the ready queue.
Context switchتبديل السياق
When the CPU switches to another process, the system must save the state of the old process and load the saved state for the new process.
- The context of a process is represented in the PCB.
- Context-switch time is overhead; the system does no useful work while switching.
- The time is dependent on hardware support.
Process creationإنشاء العمليات
- Parent processes create children, which create other processes — a tree of processes; each identified by a pid.
- Restricting a child to a subset of the parent's resources prevents any process from overloading the system by creating too many subprocesses.
- UNIX: fork creates a new process; exec is used after a fork to replace the process' memory space with a new program.
Sched (pid = 0)
init (pid = 1)
inetd (pid = 140)
telnetdaemon (pid = 7776)
Csh (pid = 7778)
dtlogin (pid = 251)
Xsession (pid = 294)
sdt_shel (pid = 340)
Csh (pid = 1400)
C program forking a separate processبرنامج fork
Process creation
المسألة
What does each branch of the slide 24 program do after pid = fork()?
خطوات الحل
- if (pid < 0): **error occurred** — prints "Fork Failed" and calls exit(-1).
- else if (pid == 0): this is the **child process** — execlp("/bin/ls", "ls", NULL) loads the ls program.
- else: this is the **parent process** — wait(NULL) waits for the child to complete, then prints "Child Complete" and exit(0).
النتيجة
fork() returns a negative value on error, 0 in the child, and a positive value (the child's pid) in the parent; the parent waits for the child with wait(NULL).
Process terminationإنهاء العمليات
Normal termination
- 1
The process executes its last statement and asks the OS to delete it (exit).
- 2
Output data goes from child to parent (via wait).
- 3
The process' resources are deallocated by the operating system.
The parent may terminate children (abort) when
- The child has exceeded allocated resources.
- The task assigned to the child is no longer required.
- The parent is exiting — some OSs do not allow a child to continue if its parent terminates: all children terminated — cascading termination.
الخلاصة
أنهيت الدرس
الخطوة التالية: ثبّت المعلومات بالبطاقات، ثم اختبر نفسك بالأسئلة.