Process States: Difference between revisions

From COMP15212 Wiki
pc>Yuron
No edit summary
 
gravatar D73083ds [userPHRhYmxlIGNsYXNzPSJ0d3BvcHVwIj48dHI+PHRkIGNsYXNzPSJ0d3BvcHVwLWVudHJ5dGl0bGUiPkdyb3Vwczo8L3RkPjx0ZD51c2VyPGJyIC8+PC90ZD48L3RyPjwvdGFibGU+] (talk | contribs)
m (fix missing ])
 
(3 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{#set: Priority=6 | Summary=The basic data behind <i>scheduling</i> processes.}}<!--
{{#set: Priority=6 | Summary=The basic data behind <i>scheduling</i> processes.}}<!--
-->{{Path|Processes|10}}<!--
-->{{Path|Processes|9}}<!--
-->{{#invoke:Dependencies|add|Processes,5|Scheduler,5}}
-->{{#invoke:Dependencies|add|Processes,5|Scheduler,5}}
A ‘simple’ computer has one processor so it can execute
A ‘simple’ computer has one processor so it can execute one [[Processes|process]] at any time.  You may want to do more than
one [[Processes|process]] at any time.  You may want to do more than
this and a ‘multi-tasking’ operating system provides the illusion that you can.
this and a ‘multi-tasking’ operating system provides the
illusion that you can.


If there is more than one process to execute, one is chosen and any
If there is more than one process to execute, one is chosen and any others are queued waiting for a turn.  After some time of execution the executing process may be moved back into the queue so that another process can proceed.  The exact basis on which the processes are chosen for running or eviction depends on the particular '''[[scheduler]]''' employed.
others are queued waiting for a turn.  After some time of execution
the executing process may be moved back into the queue so that another
process can proceed.  The exact basis on which the processes are
chosen for running or eviction depends on the particular
'''[[scheduler]]''' employed.


One reason for ceasing to execute a particular process is that it cannot currently make progress; it is said to be ‘blocked’.  A process is blocked when it waiting for [[Peripheral devices|I/O devices]], [[Interprocess_Communication|communications]] etc. or it has deliberately gone to ‘[[sleep]]’ for a while.
One reason for ceasing to execute a particular process is that it cannot currently make progress; it is said to be ‘blocked’.  A process is blocked when it waiting for [[Peripheral devices|I/O devices]], [[Interprocess_Communication|communications]] etc. or it has deliberately gone to ‘[[sleep]]’ for a while.


If a process does not block, one way of scheduling other processes is called “time slicing”.  This lets a process run for a certain time and then forces it to <em>swap</em> for one of the waiting processes.  These processes are therefore either ‘running’ (the one lucky one at this moment) or ‘ready’
If a process does not block, one way of scheduling other processes is called “time slicing”.  This lets a process run for a certain time and then forces it to <em>swap</em> for one of the waiting processes.  These processes are therefore either ‘running’ (the one lucky one at this moment) or ‘ready’ (a.k.a. ‘waiting’) for their turn.
(a.k.a. ‘waiting’) for their turn.


[[Image:process_states.png|link=|alt=process_states]]
[[Image:process_states.png|link=|alt=process_states]]
<blockquote>
<blockquote>
Example: a word processor reads characters from the keyboard.  When
Example: a word processor reads characters from the keyboard.  When it is ready for the next character it will become ‘blocked’ until you press a key – a long time as far as the computer is concerned.  When you press a key the blocked process becomes ready and will be run in the (hopefully near) future.
it is ready for the next character it will become
‘blocked’ until you press a key – a long time as far as
the computer is concerned.  When you press a key the blocked process
becomes ready and will be run in the (hopefully near) future.
</blockquote>
</blockquote>


Line 42: Line 30:


<blockquote>
<blockquote>
And here we see a classic Finite State Machine
And here we see a classic Finite State Machine ([https://en.wikipedia.org/wiki/Finite-state_machine FSM])!
([https://en.wikipedia.org/wiki/Finite-state_machine FSM])!
</blockquote>
</blockquote>
This model suffices most of the time.  Sometimes some other states are included – e.g. for when processes are created or terminate.  A [https://en.wikipedia.org/wiki/Process_state more sophisticated explanation] may also include them.
This model suffices most of the time.  Sometimes some other states are included – e.g. for when processes are created or terminate.  A [https://en.wikipedia.org/wiki/Process_state more sophisticated explanation] may also include them.
Line 52: Line 39:


=== Queuing ===
=== Queuing ===
Any number of processes can be ‘Ready’ to be run at a
Any number of processes can be ‘Ready’ to be run at a given time.  There is therefore a <strong>ready queue</strong> of processors waiting their turn for scheduling.
given time.  There is therefore a <strong>ready queue</strong> of processors
waiting their turn for scheduling.


Any number of processes can be ‘Blocked’ at a given time.
Any number of processes can be ‘Blocked’ at a given time. However processes can be <em>blocked for different reasons</em>.  For an communications process, such as a [[Pipes|pipe]] an input or an output should only ever ‘belong’ to a single process, so (at
However processes can be <em>blocked for different reasons</em>.  For an
most) one task will block waiting for that.  On the other hand, some blocks (e.g. [[Sleep|<code>sleep()</code>]] may also have a queue of waiting processes.
communications process, such as a [[Pipes|pipe]] an input or an output
should only ever ‘belong’ to a single process, so (at
most) one task will block waiting for that.  On the other hand, some
blocks (e.g. [[Sleep|<code>sleep()</code>]] may also have a queue of waiting
processes.


=== [[Multiprocessors|Multicore processors]] ===
=== [[Multiprocessors|Multicore processors]] ===
With a single core processor only one process can be
With a single core processor only one process can be ‘Running’ at any time.  With more cores, more processes can be running, assuming they are available.  (If not, then the cores are [[idle]]).
‘Running’ at any time.  With more cores, more processes
can be running, assuming they are available.  (If not, then the cores
are [[idle]).
----
----
 
{{BookChapter|3.1.2|107-109}}
{{PageGraph}}
{{PageGraph}}
{{Category|Processes}}
{{Category|Processes}}

Latest revision as of 14:59, 3 June 2023

On path: Processes 1: Processes • 2: Context • 3: Process Control Block (PCB) • 4: Multi Threading • 5: Threads • 6: Interprocess Communication • 7: Process Scheduling • 8: Scheduler • 9: Process States • 10: Process Priority
Depends on ProcessesScheduler

A ‘simple’ computer has one processor so it can execute one process at any time. You may want to do more than this and a ‘multi-tasking’ operating system provides the illusion that you can.

If there is more than one process to execute, one is chosen and any others are queued waiting for a turn. After some time of execution the executing process may be moved back into the queue so that another process can proceed. The exact basis on which the processes are chosen for running or eviction depends on the particular scheduler employed.

One reason for ceasing to execute a particular process is that it cannot currently make progress; it is said to be ‘blocked’. A process is blocked when it waiting for I/O devices, communications etc. or it has deliberately gone to ‘sleep’ for a while.

If a process does not block, one way of scheduling other processes is called “time slicing”. This lets a process run for a certain time and then forces it to swap for one of the waiting processes. These processes are therefore either ‘running’ (the one lucky one at this moment) or ‘ready’ (a.k.a. ‘waiting’) for their turn.

process_states

Example: a word processor reads characters from the keyboard. When it is ready for the next character it will become ‘blocked’ until you press a key – a long time as far as the computer is concerned. When you press a key the blocked process becomes ready and will be run in the (hopefully near) future.

  • A process which is ready may:
    • be scheduled by the OS and set running
    • be terminated by some outside influence (e.g. ‘kill’)
  • A process which is running may:
    • deliberately yield execution (becoming ready)
    • terminate itself (job complete)
    • be terminated by some outside influence (e.g. ‘kill’)
  • A process which is blocked may:
    • become unblocked and become ready (e.g. because …)
      • I/O has become ready
      • time has advanced
    • be terminated by some outside influence (e.g. ‘kill’)

And here we see a classic Finite State Machine (FSM)!

This model suffices most of the time. Sometimes some other states are included – e.g. for when processes are created or terminate. A more sophisticated explanation may also include them.

Demonstration

The process states should be evident if you visit the (interactive!) demonstration of a (simple!) scheduler.

Queuing

Any number of processes can be ‘Ready’ to be run at a given time. There is therefore a ready queue of processors waiting their turn for scheduling.

Any number of processes can be ‘Blocked’ at a given time. However processes can be blocked for different reasons. For an communications process, such as a pipe an input or an output should only ever ‘belong’ to a single process, so (at most) one task will block waiting for that. On the other hand, some blocks (e.g. sleep() may also have a queue of waiting processes.

Multicore processors

With a single core processor only one process can be ‘Running’ at any time. With more cores, more processes can be running, assuming they are available. (If not, then the cores are idle).


Also refer to: Operating System Concepts, 10th Edition: Chapter 3.1.2, pages 107-109


Articles on Processes
About this resource • Atomicity • Containers • Context • Context Switching • Daemons • Fork Unix • Hypervisor • Idle • Interprocess Communication • Multi Threading • Mutual exclusion • Pipes • Pointer Arithmetic • Process Control Block (PCB) • Process Priority • Process Scheduling • Process States • Processes • Queues • Queues Extra • Race Conditions • Real Time • Resources • Scheduler • Signal and Wait • Sleep • Starvation • Synchronisation • Thrashing • Threads • Unix Signals