Processesالعمليات

الشريحة 1 من 13

مقدمة الفصل

ماذا ستتعلم في هذا الفصل

  1. The notion of a process — a program in execution — and what it includes.
  2. Process states, the state diagram and the process control block (PCB).
  3. Process scheduling: scheduling queues, long-, short- and medium-term schedulers, context switch.
  4. Operations on processes: creation (fork, exec) and termination.
تفاصيل المصدرشرائح الفصل 1b · الشرائح ⁦2–4⁩
المصدر
شرائح الفصل 1b · الشرائح ⁦2–4⁩
ملاحظات حول المصدر (1)
  • الشريحة 4 تذكر «Threads» في المخطط، ولا توجد شريحة عنها في هذا الملف.

What is a process?مفهوم العملية

The process concept

Process
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.
Process in memory (slide 6), from address max down to 0
RegionNote
stack
  • at the top (max)
  • grows down
(free space)between stack and heap
heapgrows up
data
textat address 0

Which of the following is NOT part of a process?

تفاصيل المصدرشرائح الفصل 1b · الشرائح ⁦5–6⁩
المصدر
شرائح الفصل 1b · الشرائح ⁦5–6⁩

Process statesحالات العملية

تذكّر معنى كل حالة قبل الكشف.

  1. new
  2. running
  3. waiting
  4. ready
  5. terminated
تفاصيل المصدرشرائح الفصل 1b · الشريحة ⁦7⁩
المصدر
شرائح الفصل 1b · الشريحة ⁦7⁩

Diagram of process stateمخطط الحالات

Process states and the state diagram

Transitions of the state diagram (slide 8)
FromمنToإلىLabel on the diagram (slide 8)التسمية في المخطط
newreadyadmitted
readyrunningscheduler dispatch
runningreadyinterrupt
runningwaitingI/O or event wait
waitingreadyI/O or event completion
runningterminatedexit

On the state diagram, the I/O operation a process was waiting for completes. Which state does it move to?

تفاصيل المصدرشرائح الفصل 1b · الشريحة ⁦8⁩
المصدر
شرائح الفصل 1b · الشريحة ⁦8⁩

Process control block (PCB)كتلة التحكم PCB

PCB
The information associated with each process.
  1. 1Process state
  2. 2Program counter
  3. 3CPU registers
  4. 4CPU scheduling information
  5. 5Memory-management information
  6. 6Accounting information
  7. 7I/O status information

Which item is part of the PCB contents?

تفاصيل المصدرشرائح الفصل 1b · الشرائح ⁦9–10⁩
المصدر
شرائح الفصل 1b · الشرائح ⁦9–10⁩

Process scheduling queuesطوابير الجدولة

Job queueطابور المهام
Set of all processes in the system.
Ready queueطابور الجاهزية
Set of all processes residing in main memory, ready and waiting to execute.
Device queuesطوابير الأجهزة
Set of processes waiting for an I/O device.
  • Processes migrate among the various queues.

Which queue holds the processes residing in main memory that are ready and waiting to execute?

تفاصيل المصدرشرائح الفصل 1b · الشرائح ⁦12–14⁩
المصدر
شرائح الفصل 1b · الشرائح ⁦12–14⁩

Long-term vs short-term schedulerالمجدولات

Schedulers

Schedulers (slides 15–16)
SchedulerالمجدولSelectsيختارInvokedيُستدعىNoteملاحظة
Long-term (job scheduler)Which processes should be brought into the ready queueVery infrequently (seconds, minutes) — may be slowControls the degree of multiprogramming
Short-term (CPU scheduler)Which process should be executed next, and allocates CPUVery 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

Which scheduler controls the degree of multiprogramming?

تفاصيل المصدرشرائح الفصل 1b · الشرائح ⁦15–16⁩
المصدر
شرائح الفصل 1b · الشرائح ⁦15–16⁩

Medium-term schedulingالجدولة متوسطة المدى

Schedulers

Slide 17 figure, in words

  1. 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. 2

    The medium-term scheduler can swap out a running process: it becomes one of the partially executed swapped-out processes.

  3. 3

    Later it is swapped in back to the ready queue.

تفاصيل المصدرشرائح الفصل 1b · الشريحة ⁦17⁩
المصدر
شرائح الفصل 1b · الشريحة ⁦17⁩
ملاحظات حول المصدر (1)
  • الشريحة 17 رسم بلا نص؛ الخطوات هنا وصف لعناصر الرسم كما هي.

Context switchتبديل السياق

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.

Which statement about context-switch time is correct?

تفاصيل المصدرشرائح الفصل 1b · الشرائح ⁦18–19⁩
المصدر
شرائح الفصل 1b · الشرائح ⁦18–19⁩

Process creationإنشاء العمليات

  • Parent processes create children, which create other processes — a tree of processes; each identified by a pid.

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
  • 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.
A tree of processes on a typical Solaris (slide 25)

Sched (pid = 0)

init (pid = 1)

inetd (pid = 140)

telnetdaemon (pid = 7776)

Csh (pid = 7778)

Netscape (pid = 7785)emacs (pid = 8105)

dtlogin (pid = 251)

Xsession (pid = 294)

sdt_shel (pid = 340)

Csh (pid = 1400)

ls (pid = 2123)cat (pid = 2536)
pageout (pid = 2)fsflush (pid = 3)

In UNIX, which system call is used after a fork to replace the process' memory space with a new program?

تفاصيل المصدرشرائح الفصل 1b · الشرائح ⁦21, 22, 25⁩
المصدر
شرائح الفصل 1b · الشرائح ⁦21, 22, 25⁩

C program forking a separate processبرنامج fork

Process creation

المسألة

What does each branch of the slide 24 program do after pid = fork()?

تفاصيل المصدرشرائح الفصل 1b · الشريحة ⁦24⁩
المصدر
شرائح الفصل 1b · الشريحة ⁦24⁩
ملاحظات حول المصدر (1)
  • أن fork تعيد pid الابن في الأب استنتاج من شرط «else» في البرنامج؛ الشريحة نفسها تعرض الشروط الثلاثة دون شرح القيم.

Process terminationإنهاء العمليات

Normal termination

  1. 1

    The process executes its last statement and asks the OS to delete it (exit).

  2. 2

    Output data goes from child to parent (via wait).

  3. 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.

In some operating systems, when a parent terminates all of its children are terminated too. What is this called?

تفاصيل المصدرشرائح الفصل 1b · الشريحة ⁦26⁩
المصدر
شرائح الفصل 1b · الشريحة ⁦26⁩

الخلاصة

تفاصيل المصدر
المصدر
شرائح الفصل 1b

خريطة الفصل