Sleep: Difference between revisions

From COMP15212 Wiki
gravatar Yuron [userbureaucratinterface-adminsysopPHRhYmxlIGNsYXNzPSJ0d3BvcHVwIj48dHI+PHRkIGNsYXNzPSJ0d3BvcHVwLWVudHJ5dGl0bGUiPkdyb3Vwczo8L3RkPjx0ZD51c2VyPGJyIC8+YnVyZWF1Y3JhdDxiciAvPmludGVyZmFjZS1hZG1pbjxiciAvPnN5c29wPGJyIC8+PC90ZD48L3RyPjwvdGFibGU+] (talk | contribs)
m (1 revision imported)
pc>Yuron
No edit summary
Line 4: Line 4:
Note: this article is about a process becoming [[Process_States|blocked]] for a while on a timer.  It is different from the process-synchronisation “[[Signal and Wait|sleep]]”.
Note: this article is about a process becoming [[Process_States|blocked]] for a while on a timer.  It is different from the process-synchronisation “[[Signal and Wait|sleep]]”.
</blockquote>
</blockquote>
“Sleep” is a Unix name for a process suspended
“Sleep” is a Unix name for a process suspended ([[Process_States|blocked]]) waiting for a time.
([[Process_States|blocked]]) waiting for a time.
<blockquote>
<blockquote>
<strong>Experiment</strong>: try: “<code>sleep 5; echo Wake up.</code>” in a
<strong>Experiment</strong>: try: “<code>sleep 5; echo Wake up.</code>” in a Unix shell.
Unix shell.
</blockquote>
</blockquote>
Any number (within reason!) of processes may be sleeping at the same
Any number (within reason!) of processes may be sleeping at the same time.  As there is not ‘any number’ of <em>hardware</em> clocks available, it is likely that all sleeping processes will be [[Queues|<strong>queued</strong>]], sorted chronologically and rescheduled (unblocked) by a timer <strong>interrupt</strong>.
time.  As there is not ‘any number’ of <em>hardware</em> clocks
available, it is likely that all sleeping processes will be
[[Queues|<strong>queued</strong>]], sorted chronologically and rescheduled
(unblocked) by a timer <strong>interrupt</strong>.


[[Image:timer_queue.png|link=|alt=Timer queue]]
[[Image:timer_queue.png|link=|alt=Timer queue]]


Inside a C program, the library call <code>sleep(<seconds>)</code> will provide
Inside a C program, the library call <code>sleep(<seconds>)</code> will provide the appropriate [[System_Calls|system call]].
the appropriate [[System_Calls|system call]].
<blockquote>
<blockquote>
<strong>Exercise</strong>: write a little application which prints output at a
<strong>Exercise</strong>: write a little application which prints output at a human-readable rate using <code>sleep()</code> calls to regulate progress. (There are some ‘hints’ in <code>file_input.c</code>, but try and do without.)
human-readable rate using <code>sleep()</code> calls to regulate progress.
(There are some ‘hints’ in <code>file_input.c</code>, but try and do without.)
</blockquote>
</blockquote>
----
----
{{PageGraph}}
{{PageGraph}}
{{Category|Processes}}
{{Category|Processes}}

Revision as of 13:30, 4 August 2019

Depends on SchedulerProcess States

Note: this article is about a process becoming blocked for a while on a timer. It is different from the process-synchronisation “sleep”.

“Sleep” is a Unix name for a process suspended (blocked) waiting for a time.

Experiment: try: “sleep 5; echo Wake up.” in a Unix shell.

Any number (within reason!) of processes may be sleeping at the same time. As there is not ‘any number’ of hardware clocks available, it is likely that all sleeping processes will be queued, sorted chronologically and rescheduled (unblocked) by a timer interrupt.

Timer queue

Inside a C program, the library call sleep(<seconds>) will provide the appropriate system call.

Exercise: write a little application which prints output at a human-readable rate using sleep() calls to regulate progress. (There are some ‘hints’ in file_input.c, but try and do without.)



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