*BSD News Article 6025


Return to BSD News archive

Path: sserve!manuel!munnari.oz.au!sgiblab!darwin.sura.net!haven.umd.edu!uunet!vtserf!csugrad!briggs
From: briggs@csugrad.cs.vt.edu (Occasionally Allen)
Newsgroups: comp.unix.bsd
Subject: Re: Question about the OS running progs???
Message-ID: <BvM4nx.731@csugrad.cs.vt.edu>
Date: 4 Oct 92 19:55:09 GMT
References: <1992Oct4.174420.7664@news.ysu.edu>
Organization: Virginia Tech Computer Science Dept, Blacksburg, VA
Lines: 38

In article <1992Oct4.174420.7664@news.ysu.edu> ae007@yfn.ysu.edu (Daniel Newcombe) writes:
>If gcc compiles to straight 80x86 code, then how does the OS
>handle running multiple programs?  I guess what I really want
>to know is how the OS knows that after X amount of instructions
>have been run, it is time to give control to another process for
>X amount of instructions?

Since you mention that you are taking OS, I will point you to your
book for a more thorough coverage of "multitasking."  In a nutshell,
basic case, the compiler/assembler/linker creates an executable
program that consists of 80x86 (or whatever processor) non-privileged
instructions.  When the user is running any process, they have full
control of the processor.  In most cases, the processor is in a "user"
state so that privileged instructions will cause some sort of hardware
trap that the kernel can handle.  While the processor is running, a
clock is generating interrupts at specified intervals.  When such an
interrupt occurs, the processor is switched into a supervisory state
and a piece of the kernel takes over to save the current state of the
running process and restore the state of the next process on the queue.
When this is done, the interrupt handler exits and the new process
starts execution again.

If the time slices are short enough, it looks like the processes are
running "at the same time."  This is, of course, a very simple case and
I've left out (or glossed over) a lot of details like "what constitutes
the current state of a process?" and "what if I'm waiting for an I/O
operation and don't need my clock cycles?  Can I give up control of the
CPU?"

Do look it up in your book, or if your book doesn't cover it well, check
out books by Tannenbaum or Deitel.

-allen
-- 
Allen Briggs          \ People hurry by so quickly
briggs@csugrad.cs.vt.edu | Don't they hear the melodies
Computer Science      / In the chiming and the clicking
Virginia Tech      / And the laughing harmonies.       (Joni Mitchell)