CS 454 - PowerPoint PPT Presentation

1 / 15
About This Presentation
Title:

CS 454

Description:

Portability of Code: It is not always possible to access global variables, such ... When a program calls a subroutine, the code is always part of the final object ... – PowerPoint PPT presentation

Number of Views:29
Avg rating:3.0/5.0
Slides: 16
Provided by: christophe163
Category:
Tags: code

less

Transcript and Presenter's Notes

Title: CS 454


1
CS 454
  • Process State Transitions and System Calls

2
  • Why use getpid() instead of currpid?
  • Portability of Code It is not always possible
    to access global variables, such as currpid, from
    any process in some operating systems.
  • What is wrong with kill()?
  • It does not follow the C calling convention. The
    return address is not right above the arguments
    in the stack the process ID is. The arguments
    are therefore not at the correct offset with
    respect to the base pointer. It will try to take
    the PID as argument 0.

3
Process State Transitions
4
Process State Transitions
  • Suspend (suspend.c)
  • check pid
  • check for current or ready
  • if ready then
  • dequeue the process from the ready queue
  • put it in suspended state

5
Process State Transitions
  • Suspend (suspend.c)
  • if current then
  • put it in suspended state
  • call resched(), which calls ctxsw()
  • NOTE
  • system calls suspend, resume, kill, resched
  • utility functions getprio, getpid, chprio

6
System Calls
  • The precautions, that system calls take to verify
    that an operation is illegal, make the general
    purpose subroutines that can be invoked by any
    process at any time.
  • System calls stand between a naive user program
    and the rest of the operating system, which must
    protect the internal system from illegal use.

7
System Calls
  • System calls define the exterior of the OS by
    providing an interface through which the user
    accesses all system services.
  • Difference between library and system calls
  • When a program calls a subroutine, the code is
    always part of the final object program, even if
    it was linked in from a library.

8
System Calls
  • Difference between library and system calls
  • With a system call, the major part of the code
    excecuted is actually part of the kernel itself
    and not the calling program.
  • In other word, the calling program is making
    direct use of the facilities provided by the
    kernel.

9
Chapter 6 Process Coordination
  • Look at Semaphores and their functions
  • wait(sem)
  • signal(sem)
  • screate(count)
  • newsem()
  • sdelete(sem)
  • sreset(sem, count)

10
When are semaphores used?
  • For the collaboration and coordination of
    processes
  • When processes used shared resources
  • i.e. the producer and consumer type of process
  • Protects the shared resource

11
What other ways can we protect shared resources?
  • Disable Interrupts
  • Not Good
  • Miss interrupts from I/O devices or other things
    that dont effect the current process
  • Performance degradation
  • Not all processes may need to access the shared
    resource

12
XINU Semaphores
  • In XINU, each semaphore has 4 fields
  • struct sentry state / used or free
    / semcount sqhead sqtail

13
Semaphore Invariant
  • A non-negative semaphore count means that the
    queue is empty. A semaphore count of negative n
    means that the queue contains n waiting processes

14
How many semaphores are needed?
  • For a producer consumer problem with one buffer
  • Similar to ex5.c page 13-14 of text
  • 2 for producer/consumer
  • What are they initialized to
  • if both 0 neither can run, both wait
  • if both 1 numbers may be produced twice

15
  • What if change which is initialized to 1 and
    which is initialized to 0?
  • if consumed 0 produced 1 then ex5.c will
    print 0 - 1999
  • if consumed 1 produced 0 then ex5.c will
    print 1 - 2000
  • if you just want mutual exclusion to the shared
    resource, just need 1 semaphore (see ex6.c on
    pages 14-15 of the text)
Write a Comment
User Comments (0)
About PowerShow.com