Operating	  Systems	  and	  Technologies	  Introduction	  	  	  Operating	  System	  viewpoints:	  	  >User	  View	  	  >H...
-­‐CPU	  Organization	  The	  central	  processing	  unit	  (CPU)	  is	  the	  portion	  of	  a	  computer	  system	  that...
• 	  Decimal	  machine	                     • 	  Each	  digit	  represented	  by	  a	  ring	  of	  10	  vacuum	  tubes.	  ...
– Performance	  increases	  about	  50%	  per	  year	  (2x	  every	  1.5	  years)	  Memory	  (DRAM)	                  – Ca...
• No	  other	  architecture	  has	  had	  any	  commercial	  success	  so	  far	         • It	  is	  significant	  that	  ...
• Computer	  simulator	         • 100	  mailboxes	               – address	  00	  -­‐	  99	               – Each	  holds	 ...
2xx	                        Subtracts	  the	  contents	  of	  mailbox	  xx	  from	  the	  calculator	  display.	          ...
04	                 902	               OUTPUT	  RESULT	  05	                 000	               The	  Little	  man	  rest	...
 	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  e.g.	  adding(+),	  subtracting(-­‐),	  multiplying(x)	  and	  d...
Address	  Bus	                         • A	  ‘road’	  for	  conveying	  addresses	  to	  memory	  or	  input/	  output	  d...
Summary	                         • Most	  of	  modern	  computer	  systems	  are	  based	  on	  von	  Neumann	  architectu...
Ex2:	  Convert	  the	  following	  binary	  numbers	  to	  decimal	  number	   a.)	  1001	                              b....
e.)	  6.25	                                                           f.)	  33	  g.)	  12.125	                            ...
Ex:	  The	  LMC	  uses	  a	  3-­‐digit	  mailbox	  and	  the	  following	  op-­‐code,	  which	  are	  used	  to	  write	  ...
Ex:	  The	  LMC	  uses	  a	  3-­‐digit	  mailbox	  and	  the	  following	  op-­‐code,	  which	  are	  used	  to	  write	  ...
Operating	  Systems,	  Processes	  and	  Inter-­‐Process	  Communication	                                                 ...
– Execute	  user	  programs	  and	  make	  solving	  user	  problems	  easier.	              – Make	  the	  computer	  sys...
Compatible	                                                                                                               ...
– Resource	  allocation	  and	  scheduling	                – Fairness/priorities/efficiency	         •   System	  structur...
Certify	  above	  controls	  are	  correct.	  Scheduling	        Resource	  allocation	  and	  scheduling	        Fairness...
Textbook	  uses	  the	  terms	  job	  and	  process	  almost	  interchangeably.	  Process	  –	  a	  program	  in	  executi...
Five-­‐state	  Model	         • Processes	  may	  be	  waiting	  for	  I/O	         • Use	  additional	  states:	         ...
– State	  usually	  set	  to	  Ready	         • Set	  links	  so	  it	  is	  in	  the	  appropriate	  queue	         • Cre...
– User	  request	  (debugging,	  background)	                  – Parent	  process	  (synchronization,	  errors)	  	  New	 ...
Direct	  Communication	         • Processes	  must	  name	  each	  other	  explicitly:	              – send	  (P,	  messag...
• The	  socket	  161.25.19.8:1625	  refers	  to	  port	  1625	  on	  host	  161.25.19.8	         • Communication	  consist...
Process	  and	  CPU	  Scheduling	  Recap	  …	  Process	  …	  Queues	         • Process	  –	  a	  program	  in	  execution;...
Process	  Scheduling	         • Decide	  what	  processes	  should	  be	  executed	  by	  processor	         • Long-­‐term...
Dispatcher	         • Dispatcher	  module	  gives	  control	  of	  the	  CPU	  to	  the	  process	  selected	  by	  the	  ...
• Suppose	  that	  the	  processes	  arrive	  in	  the	  order	  P2	  ,	  P3	  ,	  P1	  .	           The	  Gantt	  chart	 ...
Operating systems and technologies
Operating systems and technologies
Operating systems and technologies
Operating systems and technologies
Operating systems and technologies
Operating systems and technologies
Operating systems and technologies
Operating systems and technologies
Operating systems and technologies
Operating systems and technologies
Operating systems and technologies
Operating systems and technologies
Operating systems and technologies
Operating systems and technologies
Operating systems and technologies
Operating systems and technologies
Operating systems and technologies
Operating systems and technologies
Operating systems and technologies
Operating systems and technologies
Operating systems and technologies
Operating systems and technologies
Operating systems and technologies
Operating systems and technologies
Operating systems and technologies
Operating systems and technologies
Operating systems and technologies
Operating systems and technologies
Operating systems and technologies
Operating systems and technologies
Operating systems and technologies
Operating systems and technologies
Operating systems and technologies
Operating systems and technologies
Operating systems and technologies
Operating systems and technologies
Operating systems and technologies
Operating systems and technologies
Operating systems and technologies
Operating systems and technologies
Operating systems and technologies
Operating systems and technologies
Operating systems and technologies
Operating systems and technologies
Operating systems and technologies
Operating systems and technologies
Operating systems and technologies
Operating systems and technologies
Operating systems and technologies
Operating systems and technologies
Operating systems and technologies
Operating systems and technologies
Operating systems and technologies
Operating systems and technologies
Operating systems and technologies
Operating systems and technologies
Upcoming SlideShare
Loading in …5
×

Operating systems and technologies

4,295 views

Published on

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
4,295
On SlideShare
0
From Embeds
0
Number of Embeds
335
Actions
Shares
0
Downloads
31
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Operating systems and technologies

  1. 1. Operating  Systems  and  Technologies  Introduction      Operating  System  viewpoints:    >User  View    >High  Level  View  (System  view)    >User  View   -­‐Varies  interface  being  used.   If  a  personal  computer       -­‐Easy  to  use     -­‐High  performance  without  regard  to  the  effectiveness  of  the  system  is  low  or  not.   If  the  computer  connects  Internet  is  called  network  system       -­‐Requires  sharing  of  system  resources  and  exchanging  information  between  them.         The  operating  system  much  is  designed  system  resources  such  as  CPU,  I/O  devices  are  used  most  effective.    >High  Level  View  (System  view)     -­‐Resources  allocate       Computer  system  has  many  resources  such  as  CPU  time,  memory  space,  file  storage  space,  I/O  devices  that  may  required  to  solve  the  problem     -­‐Program  controller         Control  devices  –  transmit  information,  manage  the  execution  of  user  programs  to  prevent  errors  and  improper  use  of  the  computer.   Input   Computer   Output    Computer  system  –  overview    -­‐Motherboard    Motherboard  is  the  main  circuit  board  in  a  computer,  provides  a  way  for  hardware  in  a  computer  to  communicate  with  each  other.  -­‐Interconnect  between  computer  components     I/O   CPU         Memory     1  
  2. 2. -­‐CPU  Organization  The  central  processing  unit  (CPU)  is  the  portion  of  a  computer  system  that  carries  out  the  instructions  of  a  computer  program,  to  perform  the  basic  arithmetical,  logical,  and  input/output  operations  of  the  system  -­‐Memory  Memory  is  an  organisms  ability  to  store,  retain,  and  recall  information  and  experiences  -­‐Input/Output    Communication  between  an  information  processing  system  (such  as  a  computer),  and  the  outside  world,  possibly  a  human,  or  another  information  processing  system.  Inputs  are  the  signals  or  data  received  by  the  system,  and  outputs  are  the  signals  or  data  sent  from  it.      Computer  System  Hierarchy   Electonic   Signal   Machine   code   Assembly  Language   Operating  System   High  Level  Language   Application  Software            User      A  brief  history  of  computers  -­‐The  first  generation  –  Vacuum  Tubes  -­‐The  second  generation  –  Transistors  -­‐The  third  generation  –  Integrated  circuit  -­‐The  fourth  generation  –  VLSI    The  first  Generation  -­‐  Vacuum  Tubes  (1945  -­‐1955)  ENIAC  (1943  -­‐  1946)   •  Intended  for  calculating  range  tables  of  aiming  artillery   •  Consisted  of  18000  tubes,  1500  relays,  weight  30  tons,  consumed  140  KW     2  
  3. 3. •  Decimal  machine   •  Each  digit  represented  by  a  ring  of  10  vacuum  tubes.   • Programmed  with  multi-­‐position  switches  and  jumper  cables.  John  von  Neumann  (1945  -­‐1952)  more  lately  …   •  Originally  a  member  of  the  ENIAC  development  team.   •  First  to  use  binary  arithmetic   •  Architecture  consists  of:  Memory,  ALU,  Program  control,  Input,  Output   •  Stored-­‐program  concept  -­‐  main  memory  store  both  data  and  instructions    The  Second  Generation  -­‐  Transistors  (1955  -­‐1965)  Transistors   •  Transistor  was  invented  in  1948  at  Bell  Labs   •  DEC  PDP-­‐1,  first  affordable  microcomputer  ($120k),  performance  half  that  of        IBM  7090  (the  fastest  computer  in  the  world  at  that  time,  which  cost  millions)   •  PDP-­‐8,  cheap  ($16,000),  the  first  to  use  single  bus  CDC  6600  (1964)   •  An  order  of  magnitude  faster  than  the  mighty  IBM  7094   •  First  highly  parallelized  machine  (up  to  10  instructions  in  parallel)  Burroughs  B5000   •  First  to  emphasise  software  and  high  level  programming  languages  (Algol  60)    The  Third  Generation  -­‐  Integrated  Circuits  (1965  -­‐1980)   •  IBM  System/360   •  Family  of  machines  with  same  assembly  language   •  Designed  for  both  scientific  and  commercial  computing   •  DEC  PDP-­‐11   •  Very  popular  with  universities,  maintained  DECs  lead  in  microcomputer  market    The  Fourth  Generation  -­‐  VLSI  (1980  -­‐  ?)   •  Lead  to  PC  revolution   •  High  performance,  low  cost    Moore’s  Law     • Transistor  density  on  a  microprocessor  will  double  every  18  to  24  months   • Computer  will  double  in  power  roughly  every  two  years,  but  cost  only  half  as  much    Technology  Trends  Processor   – Logic  Capacity  increases  about  30%  per  year       3  
  4. 4. – Performance  increases  about  50%  per  year  (2x  every  1.5  years)  Memory  (DRAM)   – Capacity  increases  about  60%  per  year  (4x  every  3  years)   – Performance  increases  3.4%  per  year  Disk   – Capacity  increases  60%  per  year   – Performance  increases  3.4%  per  year  Network  Bandwidth   – Bandwidth  increasing  more  than  100%  per  year!    The  IAS  (von  Neumann)  Machine    *Key  concepts  of  von  Neumann  architecture  include  -­‐Stored  program  concept  -­‐Binary  representation  is  the  basis  for  storing  data  in  computer  memory  -­‐Memory  is  addressed  linearly  -­‐Memory  addressed  by  the  location  number  without  regard  to  the  contents  -­‐Instructions  executed  in  sequence  unless  an  instruction  or  outside  events  cause  branch    Main  memory  storing  programs  and  data  –  1000  storage  locations  ALU  operating  on  binary  data  Control  unit  interpreting  instructions  from  memory  and  executing  Input  and  output  equipment  operated  by  control  unit    Almost  all  of  today’s  computers  have  the  same  general  structure  as  the  IAS  -­‐  referred  to  as    von  Neumann  machines.    The  structure  of  IAS   computer     Arithmetic     And         Logic  Unit           Input   Main       Output     Memory   Equipment       Program       Control  Unit      Some  Observations  Regarding  Computer  Architecture   • Between  1945  and  1951,  von  Neumann  architecture   • Other  experimental  architectures  have  been  developed  and  built   • von  Neumann  architecture  continues  to  be  the  standard  architecture  for  computer     4  
  5. 5. • No  other  architecture  has  had  any  commercial  success  so  far   • It  is  significant  that  in  a  field  where  technological  changes  happens  almost  overnight,   the  architecture  of  computers  is  virtually  unchanged  since  1951    How  Does  a  Computer  Work?  Hardware  needs  software   • Software  is  a  program  that  consists  of  a  series  of  instructions  (and  data)  for  performing   some  designated  tasks.   • CPU  runs  a  program  by  executing  the  instructions  one  by  one.     • A  program  is  stored  in  the  main  memory  when  it  is  executed.      Five  Classic  Components  of  a  Computer   *Control  gives  directions  to  the  other               components   – Examples:    Bus  controller,  memory   management  unit   *Datapath  performs  arithmetic  and  logic  operations     – Examples:    Adders,  multipliers,  shifters   Memory  holds  data  and  instructions   – Examples:    Cache,  main  memory,  disk     Input  writes  data  to  the  computer  (memory)   – Examples:    Keyboard,  mouse,  joystick   Output  reads  data  from  the  computer   – Examples:    Monitor,  sound  card    The  Little  Man  Computer  (LMC):  Physical  Layout                                 5  
  6. 6. • Computer  simulator   • 100  mailboxes   – address  00  -­‐  99   – Each  holds  3-­‐digit  decimal  number   • Calculator   – Enter  number   – Temporarily  hold  number     – Add  and  Subtraction   – Display  3  digits   • Hand  counter   – Reset  button   – Instruction  counter   • Little  Man   • In/Out  Basket    The  Little  Man  Computer:  Communication  with  outside  World  >A  user  outside  the  mailroom  communicate  with  the  little  man  by   – Putting  a  3-­‐digit  into  the  in  basket   – Retrieving  a  3-­‐digit  from  the  out  basket  >Apart  from  the  reset  button,  all  communication  between  the  LMC  and  the  outside  world  takes  place  using  3-­‐digit  numbers    The  Little  Man  Computer:  Operation   • A  small  group  of  instructions,  each  consists  of  a  single  digit   • The  first  digit  of  a  3-­‐digit  number  is  used  to  tell  the  Little  Man  which  operation  to   perform.     • In  some  cases,  the  Little  Man  is  required  to  use  a  particular  mailbox  to  store  or  retrieve   data   • The  3  digits  can  be  used  to  give  instructions  to  the  Little  Man  according  to  Operation   Code  (Op-­‐Code)   3  instruction   25  mailbox   address   Operation  Code    (Op-­‐Code)    The  Little  Man  Computer:  Instruction  Set   FORMAT    MEANING   000   Stops  the  Computer  -­‐  the  Little  Man  rests.   1xx   Adds  the  contents  of  mailbox  xx  to  the  calculator  display.     6  
  7. 7. 2xx   Subtracts  the  contents  of  mailbox  xx  from  the  calculator  display.   3xx   Stores  the  calculator  value  into  mailbox  xx.   4xx   Stores  the  address  portion  of  the  calculator  value  (last  2  digits)  into  the   address  portion  of  the  instruction  in  mailbox  xx.   5xx   Loads  the  contents  of  mailbox  xx  into  the  calculator.   6xx   This  instruction  sets  the  instruction  counter  to  the  number  xx,  thus   effectively  branching  to  mailbox  xx     7xx   IF  the  calculator  value  is  zero,  THEN  set  the  instruction  counter  to  the   number  xx,  thus  effectively  branching  to  mailbox  xx.     8xx   IF  the  calculator  value  is  positive  (or  zero),  THEN  set  the  instruction   counter  to  the  number  xx,  thus  effectively  branching  to  mailbox  xx.     901   Read  a  number  from  the  IN  basket  and  key  it  into  the  calculator.   902   Copy  the  number  in  the  calculator  onto  a  slip  of  paper  and  place  it  into   the  OUT  basket.    The  Little  Man  Computer:  Execute  Program   >To  run  an  LMC  program  we  must  carry  out  the  following  steps:   •  Load  the  instructions  into  the  mailboxes,  starting  with  mailbox  00.     • Place  the  data  to  be  used  by  the  program  in  the  IN  basket,  in  the  order  in  which  the   program  will  use  these  data.     • Press  the  RESET  BUTTON  to  set  the  Instruction  Counter  to  00  and  to  also  wakeup  the   Little  Man.    Then     1.  The  Little  Man  looks  into  the  Instruction  Counter   2.  The  Little  Man  finds  the  mailbox  whose  address  has  the  value  in  the  Instruction   Counter  and  fetches  the  3-­‐digit  number  from  the  mailbox.   3.  The  Little  Man  goes  over  to  increase  the  instruction  counter  by  1   4.  The  Little  Man  executes  the  instruction  found  in  the  mailbox   5.  The  Little  Man  repeats  the  by  going  to  1    The  Little  Man  Computer:  Program  Example  Write  a  LMC  program,  which  adds  two  numbers  together    Mailbox   Code   Instruction  Description  01   901   INPUT  02   399   STORE  DATA  to  mailbox  no.  99  03   INPUT   ADD  the  1st  number  to  2nd  number     7  
  8. 8. 04   902   OUTPUT  RESULT  05   000   The  Little  man  rest  99    Data    The  Little  Man  Computer  (LMC)  -­‐  Three  main  aspects   1. Input/Output     • These  are  used  so  the  LMC  can  communicate  with  the  outside  world.   2. Central  Processing  Unit     • Contains  the  core  of  the  computer:  calculator,  reset  button,  instruction  counter   and  the  little  man.   3. Memory     • The  mailboxes  from  00  -­‐  99  each  containing  one  3-­‐digit  number  representing   instructions  or  data.    Central  Processing  Unit  (CPU)  CPU  is  A  hardware  device  (VLSI  chip)  that  integrates  millions  of  transistors  into  a  silicon  chip.     • Lies  at  the  heart  of  a  computer,     •  Executes  instructions  of  a  program,     •  Controls  all  operations  accordingly.            CPU  Architecture    >Arithmetic  Logic  Unit  (ALU)   • Arithmetic  Logic  Unit  (ALU):  primarily  constructed  by  logic  gates  (full  adders)   • It  performs   – Basic  arithmetic  calculations:       8  
  9. 9.                                        e.g.  adding(+),  subtracting(-­‐),  multiplying(x)  and  dividing(/).     – Logic  operations:                                            e.g.  OR,  AND,  NOT,  (Left  or  Right)  Shift,  etc.     • ALU  gets  control  signals  from  the  Control  Unit  to  carry  out  instructions  one  by  one.    >Control  Unit   • One  of  the  most  important  parts  in  a  CPU.     • Consists  of  decoding,  timing  and  control  logic  circuits.       • Main  functions:   – To  decode  instructions,   – To  create  control  signals,  which  tell  the  ALU  and  the  Registers  how  to  operate,   what  to  operate  on,  and  what  to  do  with  the  result.     – To  make  sure  everything  happens  in  the  right  place  at  the  right  time,  with  a  clock.  >Registers   • A  mini-­‐storage  area  built  with  flip-­‐flops  inside  CPU     – PC  (Program  Counter):  Holds  address  of  instruction  being  executed.     – IR  (Instruction  Register):  Holds  instruction  while  its  decoded/executed.   – ACC  (Accumulator):  Result  of  ALU  operations   – MBR  (Memory  Buffer  Register):  Temporarily  holds  the  instruction/data  fetched   from  the  memory  unit.   – MAR  (Memory  Address  Register):  holds  address.   • ALU  can  retrieve  information  (instruction  or  data)  quickly.  >System  BUS  Structure              System  bus  consists  of  3  functional  groups  of  lines:   • Data  bus  lines   • Control  bus  lines     • Address  bus  lines                    Data  Bus   • Bi-­‐directional  path  for  transmitting  data  between  the  CPU  and  memory,  and   peripherals.   • Width  of  data  bus:  number  of  bits  can  be  transferred  at  a  time   – E.g.  8,  16,  32,  or  64  lines,  each  for  one  bit  binary  data,     • The  width  of  data  bus  is  one  key  factors  in  determining  overall  system  performance.     9  
  10. 10. Address  Bus   • A  ‘road’  for  conveying  addresses  to  memory  or  input/  output  devices.   • The  number  of  address  lines,  or  width,  determines  maximum  capacity  of  addresses  a   CPU  can  access  to,     i.e.  N  lines:    2N  addressable  memory  (and  I/O)  units,     e.g.8  address  lines:  28  =  256  addresses  from  00000000  to  11111111.  Control  Bus   • Carries  signals  to  control  the  activities  of  data/instruction  transfers  (read  or  write),  or   input/output  devices.   • The  number  of  control  bus  lines  varies,  each  is  designed  to  perform  a  specific  control   task,  e.g.                                        RD:  Read  signal                                      WR:  Write  signal                                      CLK:  system  clock  signal                                      RESET:  reset  control  signal      M68000  CPU  chip   • 64  connection  pins     – 16-­‐bit  Data  Bus  (32-­‐bit  internal).   – 24-­‐bit  address  bus  (for  16  MB).   – 21  control  pins,  e.g.                ,  Halt,  etc.   – 3  pins  for  power  supply:  Vcc,  GNDx2.      >Instruction  execution  CPU  performs  Fetch/Decode/Execute  cycle:   • Fetch  instruction  from  primary  memory   • Increment  Program  Counter   • Decode     • Execute  instruction     • Write  result  to  memory    Fetch  Time  depends  on  access  time  of  memory  and  activity  on  Bus    Decode/Execute  Time  depends  on  type  of  instruction    Instruction  Execution  Cycle                   10  
  11. 11. Summary   • Most  of  modern  computer  systems  are  based  on  von  Neumann  architecture     • Computer  components:  CPU,  Memory  and  I/O  devices     • BUS  (Control  bus,  data  bus  and  address  bus)  links  computer  components  together   • CPU  (Centre  Processing  Unit):  the  brain  of  a  computer.    Consists  of:  ALU  (Arithmetic  and   Logic  Unit),  Registers,  Control  Unit,  Internal  bus  and  Bus  Interface  Unit.     • CPU  instruction  cycle  includes:    Fetch  →  Decode  →  Execute.    The  Little  Man  Computer:  Exercise  Write  a  LMC  program  which  subtracts  the  second  input  number  from  the  first  input  number  and  outputs  the  result.  (Assumption:  first  input  number    >=  second  input  number)   Mailbox   Code   Instruction  Description   00   901   INPUT  A   01   350   STORE  DATA  to  mailbox  no.  50   02   901   INPUT  B   03   339   STORE  DATA  to  mailbox  no.39   04   550   LOAD  the  first  number   05   239   SUBSTRACT  2nd  from  1st     06     902   OUTPUT  RESULT   07   000   The  little  man  rest                                                                50  Data                                                                39  Data    Exercise  Computer  system  and  number  system  Ex1:  Find  the  word  or  phrase  from  the  list  below  that  best  matches  the  description  in  the  folloeing  question.     a) Binary  number  >  III  Base  2  number   b) Bit  >  II  Binary  digit   c) Central  processor  >  I  Active  part  of  the  computer,  following  the  instructions  of  the   programs  it  adds  numbers,  test  number,  and  so  on   d) Complier  >  VII  Program  that  translates  rom  a  higher-­‐level  notation  to  assembly   language  or  machine  code   e) Integrated  circuit  >  IV  Integrate  dozens  to  hundreds  of  transistors  into  a  single   chip   f) Memory  >  Locations  of  programs  when  they  are  running  containing  the  data   needed  as  well   g) Operating  system  >  Program  that  manages  the  sources  of  a  computer  for  the   benefit  of  the  programs  that  run  on  that  machine     h) Semiconductor  >  Substance  that  does  not  conduct  electricity  well       11  
  12. 12. Ex2:  Convert  the  following  binary  numbers  to  decimal  number   a.)  1001   b.)  0.111   c.)  0.11011   d.)  1.001   e.)  111.1011   f.)  100.01  Ex3:  Convert  the  following  decimal  number  into  binary  number  a.)  39   b.)  12  C.)  0.25   d.1/8     12  
  13. 13. e.)  6.25   f.)  33  g.)  12.125   h.)  39.125  Ex:  Discuss  the  main  components  of  the  little  man  computer  and  respond  them  to  in  a  real  computer  -­‐Mailbox  ~=  the  numbering  system  >  memory  -­‐Calculator  >  CPU/  Register    -­‐Little  man  >  Bus  system,  CPU  -­‐Instruction  locations  (hand  counter)  >  program  computer    -­‐In/Put  basket  >  Input  /  Output  device  module  -­‐Reset  button  >  Reset  power                             13  
  14. 14. Ex:  The  LMC  uses  a  3-­‐digit  mailbox  and  the  following  op-­‐code,  which  are  used  to  write  a  program.  Output  largest  number  of  two  input  number      Mailbox   Code   Instruction  Description  00   901   INPUT  A  01   399   STORE  DATA  to  mailbox   no.99  02   901   INPUT  B  03   389   STORE  DATA  to  mailbox   no.89  04   299   SUBSTRACT  the  A  to  B  (B-­‐A)  05   820   If  B-­‐A  >  0  (go  to  20)  06   599   LOAD  A  (A  is  bigger)  07   621   JUMP  to  21  07   902   OUTPUT  08   000   STOP   .   .   .   .   .   .   .   .   .   .   .   .        20   589   LOAD  B  (B  is  bigger)  21   902   OUTPUT  22   000   STOP                                     14  
  15. 15. Ex:  The  LMC  uses  a  3-­‐digit  mailbox  and  the  following  op-­‐code,  which  are  used  to  write  a  program.  Output  smallest  number  of  two  input  number      Mailbox   Code   Instruction  Description  00   901   INPUT  A  01   399   STORE  DATA  to  mailbox   no.99  02   901   INPUT  B  03   389   STORE  DATA  to  mailbox   no.89  04   299   SUBSTRACT  the  A  to  B  (B-­‐A)  05   820   If  B-­‐A  >  0  (go  to  20)  06   599   LOAD  B  (B  is  smallest)  07   621   JUMP  to  21   .   .   .   .   .   .   .   .   .   .   .   .        20   589   LOAD  A  (A  is  smallest)  21   902   OUTPUT  22   000   STOP                                         15  
  16. 16. Operating  Systems,  Processes  and  Inter-­‐Process  Communication      Recap…Computer  System  Components   • Hardware  –  provides  basic  computing  resources  (CPU,  memory,  I/O  devices).   • Operating  system  –  controls  and  coordinates  the  use  of  the  hardware  among  the   various  application  programs  for  the  various  users.   • Applications  programs  –  define  the  ways  in  which  the  system  resources  are  used  to   solve  the  computing  problems  of  the  users  (compilers,  database  systems,  video  games,   business  programs).   • Users  (people,  machines,  other  computers).      What  is  an  Operating  System  (OS)?   • A  program  that  acts  as  an  intermediary  between  an  application  program  (or  a  user)  and   the  computer  hardware   – Allocate  resources  (CPU,  Memory,  disk  space,  etc.)  between  programs  and  users   efficiently   – Allow  the  user  to  conveniently  access  data  and  programs   – Protect  the  system  from  incorrect  or  malicious  programs  and  users   • Operating  system  goals:     16  
  17. 17. – Execute  user  programs  and  make  solving  user  problems  easier.   – Make  the  computer  system  convenient  to  use.   • Use  the  computer  hardware  in  an  efficient  manner    What  is  an  OS?   • Definitions   – Resource  allocator  –  manages  and  allocates  resources   – Control  program  –  controls  the  execution  of  user  programs  and  operations  of  I/O   devices     – Kernel  –  the  one  program  running  at  all  times  (all  else  being  application  programs)   • Services  typically  provided  by  an  O.S.   – Program  Creation  (editor,  compiler)   – Program  Execution   – Access  to  I/O  devices   – Controlled  access  to  files   – System  Access  (logging  in)   – Error  detection/response   • O.S.  will  evolve  over  time  -­‐  Hardware  upgrades,  New  services    OS  History   • Serial  Processing   – Sign-­‐up  sheet  for  computer  time   – Each  user  would  set  up  the  job,  run  it,  and  collect  output   • Simple  Batch  System  (mid  1950s)   – Try  to  improve  scheduling/setup  time   – Have  a  monitor  that  loads  jobs,  when  a  job  finishes  it  jumps  to  the  monitor  that   loads  the  next  job.   • Multiprogrammed  Batch  System   – Several  programs  in  memory  at  one  time   • One  program  can  do  I/O  while  another  computes   – Needs  memory  management,  scheduling   • Time-­‐Sharing  Systems   – Allow  several  users  to  interact  with  the  system  at  the  same  time   – Single-­‐user  multitasking  (windows  95)       17  
  18. 18. Compatible   time  sharing   system   (CTSS)  –   1962   Switched   users  every   0.2  second   Supported  up   to  32  users   MULTICS   (1965)   Intended  as   the  computer   *Desirable  hardware  items:   service  for   Memory  protection   Boston   Timer   Strong   Privileged  instructions  (I/O)   influence  on   Interrupts   later  systems       Good  security,     user  interface    OS  Issues   • Process.   – Hard  to  define  formally,  but  think  of  a  running  program.   – O.S.  needs  to  maintain  proper  synchronization  between  processes  (mutual   exclusion,  avoiding  deadlock).   • Main  causes  of  errors:   – Improper  synchronization.   • Must  wait  for  someone  else  to  finish.   – Failed  mutual  exclusion.   • Assigning  two  passengers  to  the  same  seat.   – Nondeterminate  program  execution.   • Output  depends  on  other  programs.   • May  be  a  result  of  misused  common  memory.   – Deadlock.   • Two  processors  each  waiting  for  the  other  to  do  something.   • Memory  management   – Isolate  processes  from  each  other  (shared  memory  may  be  allowed).   – Automatically  move  data  between  main  memory  and  disk.   – Support  long-­‐term  storage.     • Security   – Control  use  of  the  system,  access  to  files  and  other  resources.   • Scheduling     18  
  19. 19. – Resource  allocation  and  scheduling   – Fairness/priorities/efficiency   • System  structure   – As  systems  grow  larger,  rely  on  modules,  layers  of  abstraction   • Multithreading   – Allow  a  process  to  consist  of  one  or  more  threads  that  share  memory,  files,  etc.   – Helps  with  structuring  programs   • Microkernel   – Assign  only  essential  functions  to  the  kernel  (memory,  communication)   – Other  items  run  as  user  processes   • Symmetric  multiprocessing  (SMP)   – System  may  have  two  or  more  equivalent  processors  that  share  memory,  I/O   • Distributed  operating  system  (clusters)   – Provide  illusion  of  a  single  system  from  several  entities    *Process.   Hard  to  define  formally,  but  think  of  a  running  program.   Three  main  components:     Executable  program.   Data  for  that  program.   Context  (registers,  files,  etc.)  For  the  program.   O.S.  Needs  to  maintain  proper  synchronization  between  processes  (mutual  exclusion,  avoiding   deadlock).  Main  causes  of  errors:   Improper  synchronization.   Must  wait  for  someone  else  to  finish.   Failed  mutual  exclusion.   Assigning  two  passengers  to  the  same  seat.   Nondeterminate  program  execution.   Output  depends  on  other  programs.   May  be  a  result  of  misused  common  memory.   Deadlock.   Two  processors  each  waiting  for  the  other  to  do  something.  Memory  management   Isolate  processes  from  each  other  (shared  memory  may  be  allowed).   Should  allow  only  appropriate  accesses.   Often  implemented  using  virtual  memory.   Automatically  move  data  between  main  memory  and  disk.   Support  modular  programs.   Support  long-­‐term  storage.  Security   Control  use  of  the  system,  access  to  files  and  other  resources.   Areas  of  concern  by  O.S.  Developers:   Access  control.   Information  flow  control.     19  
  20. 20. Certify  above  controls  are  correct.  Scheduling   Resource  allocation  and  scheduling   Fairness/priorities/efficiency  System  structure   As  systems  grow  larger,  rely  on  modules,  layers  of  abstraction   Electronic  circuits   Instruction  set   Procedures   Interrupts   Primitive  processes   Local  secondary  storage   Virtual  memory   Communications   File  system   Devices   Directories   User  process   Shell    Process   • A  process  is  a  program  in  execution.    A  process  needs  certain  resources,  including  CPU   time,  memory,  files,  and  I/O  devices,  to  accomplish  its  task.   • Three  main  components:     • Executable  program.   • Data  for  that  program.   • Context  (registers,  files,  etc.)  for  the  program.   • The  operating  system  is  responsible  for  the  following  activities  in  connection  with   process  management.   – Process  creation  and  deletion.   – Process  suspension  and  resumption.   – Provision  of  mechanisms  for:   • process  synchronization   • process  communication    Hard  to  define  formally,  but  think  of  a  running  program.  Three  main  components:     Executable  program.   Data  for  that  program.   Context  (registers,  files,  etc.)  For  the  program.  O.S.  Needs  to  maintain  proper  synchronization  between  processes  (mutual  exclusion,  avoiding  deadlock).    An  operating  system  executes  a  variety  of  programs:   Batch  system  –  jobs   Time-­‐shared  systems  –  user  programs  or  tasks     20  
  21. 21. Textbook  uses  the  terms  job  and  process  almost  interchangeably.  Process  –  a  program  in  execution;  process  execution  must  progress  in  sequential  fashion.    A  process  includes:   program  counter     stack   data  section        Process  Control  Block   • Identifiers   – Process,  Parent,  User   • Processor  State     Information  associated  with  each  process   – User-­‐Visible  Registers   – Control/Status  Registers   – Stack  Pointers  (User,  System)   • Process  Control  Information   – Scheduling/state,  Priority   – Data  structure  info  (links)   – Interprocess  Communication   – Privilege  Information   – Memory  Management   • User  Code   • User  Data   • System  Stack   – Resource  Ownership  and  Utilization    Process  States   • Two-­‐state  model:   – Running   – Not  Running                -­‐  may  be  held  in  a  queue   • Requirements   – Some  way  of  representing  a   process   • Must  include  state  and   memory  use   – Must  keep  track  of  processes  that  are  not  currently  running   – Dispatcher   • Moves  processes  to  the  waiting  queue   • Remove  completed/aborted  processes   • Select  the  next  process  to  run     21  
  22. 22. Five-­‐state  Model   • Processes  may  be  waiting  for  I/O   • Use  additional  states:   – Running:  currently  being  run   – Ready:  ready  to  run   – Blocked:  waiting  for  an  event  (I/O)   – New:  just  created,  not  yet  admitted  to  set  of  runnable  processes   – Exit:  completed/error  exit   • May  have  separate  waiting  queues  for  each  event        May  have  separate  waiting  queues  for  each  event    Transitions:  Null  ®  New  –  Process  is  created  New  ®  Ready  –  O.S.  is  ready  to  handle  another  process  (Memory,  CPU)  Ready  ®  Running  –  Select  another  process  to  run  Running  ®  Exit  –  Process  has  terminated  Running  ®  Ready  –  End  of  time  slice  or  higher-­‐priority  process  is  ready  Running  ®  Blocked  –  Process  is  waiting  for  an  event  (I/O,  Synchronization)  Blocked  ®  Ready  –  The  event  a  process  is  waiting  for  has  occurred,  can  continue  Ready  ®  Exit  –  Process  terminated  by  O.S.  or  parent  Blocked  ®  Exit  –  Same  reasons    Creating  a  Process   • Assign  a  unique  process  ID   • Allocate  memory  for  the  process   • Initialize  the  process  control  block   – Process  ID,  parent  ID   – Set  program  counter  and  stack  pointer  to  appropriate  values     22  
  23. 23. – State  usually  set  to  Ready   • Set  links  so  it  is  in  the  appropriate  queue   • Create  other  data  structures   – Memory,  files,  accounting   • Reasons  to  create  a  process   – Submit  a  new  batch  job/Start  program   – User  logs  on  to  the  system   – Device  driver  or  Daemon   – OS  creates  on  behalf  of  a  user    Switching  Processes   • We  will  often  switch  between  the  various  processes  in  the  system   – External  Interrupt  -­‐  time  slice  expired,  I/O  interrupt     – Internal  trap,  e.  g.,  invalid  operation   – Supervisor  call   • Steps  to  take  to  switch  processes   – Save  the  current  processor  state  (registers,  flags,  etc.)   – Set  the  program  counter  to  the  address  of  the  appropriate  routine   – Update  state  of  current  process  from  Running  to  Blocked/Ready/Exit   – Move  the  control  block  to  the  appropriate  queue   – Select  another  process  to  execute   – Move  the  control  block  from  the  appropriate  queue   – Update  the  control  block  of  the  selected  process  to  running   – Update  necessary  memory-­‐management  structures   – Restore  the  context  (registers,  etc.)  of  the  newly  selected  process    Suspending  a  Process   • May  suspend  a  process  by  swapping  part  or  all  of  it  to  disk   – Most  useful  if  we  are  waiting  for  an  event  that  will  not  arrive  soon  (printer,   keyboard)   – If  not  done  well,  can  slow  system  down  by  increasing  disk  I/O  activity                 • Reasons  to  Suspend   – Manage  Resources   – Timing  (backup  at  midnight  process)     23  
  24. 24. – User  request  (debugging,  background)   – Parent  process  (synchronization,  errors)    New  Transitions:   Blocked  ®  Blocked  Suspend  –  Swap  out  a  blocked  process  to  free  memory   Blocked  Suspend  ®  Ready  Suspend  –  Event  occurs  (O.S.  must  track  expected  event)   Ready  Suspend  ®  Ready  –  Activate  a  process  (higher  priority,  memory  available)   Ready  ®  Ready  Suspend  –  Need  to  free  memory  for  higher-­‐priority  processes   New  ®  Ready  or  Ready  Suspend  –  Can  choose  where  to  put  new  processes   Blocked  Suspend  ®  Blocked  –  Reload  process  expecting  event  soon   Running  ®  Ready  Suspend  –  Preempt  for  higher-­‐priority  process  Key  States:   Ready  –  In  memory,  ready  to  execute   Blocked  –  In  memory,  waiting  for  an  event   Blocked  Suspend  –  On  disk,  waiting  for  an  event   Ready  Suspend  –  On  disk,  ready  to  execute    Terminating  a  Process   • Need  some  way  to  indicate  a  process  is  finished  (system  call  or  instruction)   • Program  may  fail   – Protection  error   – Address  Error   – Invalid  data  operation   – Invalid  or  privileged  instruction   – I/O  Failure   – Parent  process  request   – Operator  intervention  (control-­‐C)    Inter-­‐process  Communication  (IPC)     • Mechanism  for  processes  to  communicate  and  to  synchronize  their  actions.   • Message  system  –  processes  communicate  with  each  other  without  resorting  to  shared   variables.   • IPC  facility  provides  two  operations:   – send(message)  –  message  size  fixed  or  variable     – receive(message)   • If  P  and  Q  wish  to  communicate,  they  need  to:   – establish  a  communication  link  between  them   – exchange  messages  via  send/receive   • Implementation  of  communication  link   – physical  (e.g.,  shared  memory,  hardware  bus)   – logical  (e.g.,  logical  properties)       24  
  25. 25. Direct  Communication   • Processes  must  name  each  other  explicitly:   – send  (P,  message)  –  send  a  message  to  process  P   – receive(Q,  message)  –  receive  a  message  from  process  Q   • Properties  of  communication  link   – Links  are  established  automatically.   – A  link  is  associated  with  exactly  one  pair  of  communicating  processes.   – Between  each  pair  there  exists  exactly  one  link.   – The  link  may  be  unidirectional,  but  is  usually  bi-­‐directional.    Indirect  Communication   • Messages  are  directed  and  received  from  mailboxes  (also  referred  to  as  ports).   – Each  mailbox  has  a  unique  id.   – Processes  can  communicate  only  if  they  share  a  mailbox.   • Operations   – create  a  new  mailbox   – send  and  receive  messages  through  mailbox   – destroy  a  mailbox   • Properties  of  communication  link   – Link  established  only  if  processes  share  a  common  mailbox   – A  link  may  be  associated  with  many  processes.   – Each  pair  of  processes  may  share  several  communication  links.   – Link  may  be  unidirectional  or  bi-­‐directional.   • Mailbox  sharing   – P1,  P2,  and  P3  share  mailbox  A.   – P1,  sends;  P2  and  P3  receive.   – Who  gets  the  message?   • Solutions   – Allow  a  link  to  be  associated  with  at  most  two  processes.   – Allow  only  one  process  at  a  time  to  execute  a  receive  operation.   – Allow  the  system  to  select  arbitrarily  the  receiver.    Sender  is  notified  who  the   receiver  was.     Primitives  are  defined  as:   Operations     send(A,  message)  –  send  a     message  to  mailbox  A   create  a  new  mailbox       receive(A,  message)  –  receive  a   send  and  receive  messages  through  mailbox     destroy  a  mailbox   message  from  mailbox  A      Client-­‐Server  Communication  –Sockets   • A  socket  is  defined  as  an  endpoint  for  communication.   • Concatenation  of  IP  address  and  port     25  
  26. 26. • The  socket  161.25.19.8:1625  refers  to  port  1625  on  host  161.25.19.8   • Communication  consists  between  a  pair  of  sockets.       Socket     Socket   (146.86.5.2/1625)   (161.25.19.8/80)         Host  X  (146.86.5.20)     Web  sever  (161.25.19.8/80)    Client-­‐Server  Communication  -­‐Remote  Procedure  Calls   • Remote  procedure  call  (RPC)  abstracts  procedure  calls  between  processes  on  networked   systems.   • Stubs  –  client-­‐side  proxy  for  the  actual  procedure  on  the  server.   • The  client-­‐side  stub  locates  the  server  and  marshalls  the  parameters.   • The  server-­‐side  stub  receives  this  message,  unpacks  the  marshalled  parameters,  and   peforms  the  procedure  on  the  server.      Client-­‐Server  Communication  -­‐Remote  Method  Invocation   • Remote  Method  Invocation  (RMI)  is  a  Java  mechanism  similar  to  RPCs.   • RMI  allows  a  Java  program  on  one  machine  to  invoke  a  method  on  a  remote  object.    Summary   • OS  provides  an  interface  between  a  user  of  a  computer,  an  application  program  and  the  computer   hardware   • OS  have  evolved  over  the  years   • Process  is  set  of  instructions  and  data  and  is  usually  represented  by  states   • OS  needs  to  maintain  proper  synchronization  between  processes   • Processes  use  different  ways  of  communication  to  synchronize  their  actions             26  
  27. 27. Process  and  CPU  Scheduling  Recap  …  Process  …  Queues   • Process  –  a  program  in  execution;  process  execution  must  progress  in  sequential   fashion.   • As  a  process  executes,  it  changes  state   • PCB  -­‐  Information  associated  with  each  process   • 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.   – Process  migration  between  the  various  queues.   – Starvation  –  indefinite  delay  of  a  process  due  queue  of  processes   – CPU  burst  –  processing  time  of  a  process     CPU–I/O  Burst  Cycle  CPU–I/O  Burst  Cycle   • Process  execution  consists  of  a  cycle  of  CPU     execution  and  I/O  wait.     • Maximum  CPU  utilization  obtained  with     Multiprogramming    Process  Types   • Processes  can  be  described  as  either:   – 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.   • Process  can  be  of  two  types:   – Non  preemptive  –  once  CPU  given  to  the    process  it  cannot  be  released  until  it     completes  its  CPU  burst.   – Preemptive  –  the  process  which  can  be    released  to  before  it  completes  its     CPU  burst.               27  
  28. 28. Process  Scheduling   • Decide  what  processes  should  be  executed  by  processor   • Long-­‐term  scheduler  (or  job  scheduler)     – deals  with  creating  a  new  process   – selects  which  processes  should  be  brought  into  the  ready  queue.     – is  invoked  infrequently  (seconds,  minutes)  ⇒  (may  be  slow).     • Medium-­‐term  scheduler   – deals  with  swapping  processes  in/out   • Short-­‐term  scheduler  (or  CPU  scheduler)     – selects  which  process  should  be  executed  next  and  allocates  CPU   – is  invoked  very  frequently  (milliseconds)  ⇒  (must  be  fast).   – Invoked  on:   • clock  or  I/O  interrupt   • system  call,  signal    Representation  of  Process  Scheduling      CPU  Scheduler   • Selects  from  among  the  processes  in  memory  that  are  ready  to  execute,  and  allocates   the  CPU  to  one  of  them.   • CPU  scheduling  decisions  may  take  place  when  a  process:   1.   Switches  from  running  to  waiting  state.   2.   Switches  from  running  to  ready  state.   3.   Switches  from  waiting  to  ready.   4.   Terminates.   • Scheduling  under  1  and  4  is  non  preemptive.   • All  other  scheduling  is  preemptive.     28  
  29. 29. Dispatcher   • Dispatcher  module  gives  control  of  the  CPU  to  the  process  selected  by  the  short-­‐term   scheduler;  this  involves:   – switching  context   – switching  to  user  mode   – jumping  to  the  proper  location  in  the  user  program  to  restart  that  program   • Dispatch  latency  –  time  it  takes  for  the  dispatcher  to  stop  one  process  and  start  another   running.    Scheduling  Criteria   • CPU  utilization     – keep  the  CPU  as  busy  as  possible   • Throughput     – number  of  processes  that  complete  their  execution  per  time  unit   • Turnaround  time     – amount  of  time  to  execute  a  particular  process   • Waiting  time     – amount  of  time  a  process  has  been  waiting  in  the  ready  queue   • Response  time     – amount  of  time  it  takes  from  when  a  request  was  submitted  until  the  first   response  is  produced    Scheduling  Algorithms   • First-­‐Come,  First-­‐Served  (FCFS)  Scheduling   • Shortest-­‐Job-­‐First  (SJR)  Scheduling     • Shortest-­‐Remaining-­‐Time-­‐First  (SRTF)     • Round  Robin  (RR)   • Highest  Response  Ratio  Next   • Feedback    First-­‐Come,  First-­‐Served  (FCFS)  Scheduling  Process:     P1     P2       P3     Waiting  Time    Burst  Time:     24    3      3   =Complete  time  –  Arrived  time  –  Burst  time   Waiting  time   >   P1=24-­‐0-­‐24=0           P2=27-­‐0-­‐3=24   • Suppose  that  the  processes  arrive  in  the  order:  P1,  P  2,  P3           P3=30-­‐0-­‐3=27   The  Gantt  chart  for  the  schedule  is:           P1     P2   P3       P1=24     P2=3     P3=3   CPU  Time     0       P1=24   24   27     30   P2=3   P2=3   P3=3           Average  waiting  time  =       P3=3   P3=3         (0+24+27)/3=17     29   =  
  30. 30. • Suppose  that  the  processes  arrive  in  the  order  P2  ,  P3  ,  P1  .   The  Gantt  chart  for  the  schedule  is:     P2   P3   P1     P2=3     P3=3   P1=24   CPU  Time       0   3   6   30     P2=3   P3=3   P1=24     P3=3   P1=24   Waiting  Time       =Complete  time  –  Arrived  time  –  Burst  time   P1=24     Waiting  time   >   P1=30-­‐0-­‐24=6   • Processes  queued  in  order  of  arrival         P2=3-­‐0-­‐3=0   • Runs  until  finished  or  blocks  on  I/O         P3=6-­‐0-­‐3=3   Average  waiting  time  =  (6+0+3)/3=3   • Tends  to  penalize  short  processes     – Have  to  wait  for  earlier  long  processes     • Convoy  effect  short  process  behind  long  process     • Favors  processor-­‐bound  processes     –  I/O  processes  block  quickly              Shortest-­‐Job-­‐First  (SJR)  Scheduling     • Associate  with  each  process  the  length    of  its  next  CPU  burst.    Use  these  lengths  to     schedule  the  process  with  the  shortest  time.   • Two  types:   – Nonpreemtive  version   • Select  process  with  shortest  expected  running  time     – once  CPU  given  to  the  process  it  cannot  be  preempted  until   completes  its  CPU  burst.     • Short  processes  may  still  wait  if  a  long  process  has  just  started     – Peemtive  version   • Select  process  with  shortest  expected  running  (or  remaining)  time     • May  switch  processes  when  a  new  process  arrives   – if  a  new  process  arrives  with  CPU  burst  length  less  than  remaining   time  of  current  executing  process,  preempt     • Also  called  Shortest-­‐Remaining-­‐Time-­‐First  (SRTF)  Scheduling   • Difficult  to  estimate  required  time   – Can  only  estimate  the  length  of  Next  CPU  Burst   – Can  estimate  from  previous  runs   • Tends  to  be  less  predictable   • Can  starve  long  processes   – notpreemtive  SJR  is  better  than  SRTF  (preemtive  SRJ)  in  this  regard     • Short  processes  may  still  wait  if  a  long  process  has  just  started     – SRTF  is  better  than  nonpreemptive  SRJ  in  this  regard       30  

×