System V IPC Identifiers and Keys - PowerPoint PPT Presentation

1 / 9
About This Presentation
Title:

System V IPC Identifiers and Keys

Description:

keys can be arbitrarily defined, system defined via a get' call, or defined ... always check for structures you may have inadvertently left behind when testing ... – PowerPoint PPT presentation

Number of Views:69
Avg rating:3.0/5.0
Slides: 10
Provided by: richarde78
Category:

less

Transcript and Presenter's Notes

Title: System V IPC Identifiers and Keys


1
System V IPCIdentifiers and Keys
  • IPC structures are identified by a key
  • usually defined as long integer
  • keys can be arbitrarily defined, system defined
    via a get call, or defined using the ftok()
    function
  • arbitrary definition gives rise to conflicts
  • programs must use the same key to access the same
    resource
  • typically passed from parent to child or shared
    in a header in client/server suites

2
Permissions
  • IPC structures have permissions, similar to files
  • to change permissions, process must either be the
    creator of the structure or the superuser
  • write permissions for semaphores are termed
    alter
  • there are no permissions corresponding to
    execute

3
Pros and Cons of SV-IPC
  • Pros
  • flow controlled
  • record oriented
  • not first-in, first-out limited
  • Cons
  • have to be deliberately removed
  • arent addressable with simple file I/O commands
    (open, read, write, etc.)
  • are overly complex

4
Picking Keys
  • keys may be any key_t type value
  • keys may be chosen arbitrarily
  • can result in conflicts
  • a key can be generated by the system using the
    IPC_PRIVATE keyword
  • has to somehow be made available to other
    processes wishing to use the resource
  • a key can be generated using the ftok() function
  • doesnt require shared headers or file reading

5
Message Queues
  • linked list of messages stored in the kernel
  • identified by a queue ID
  • msgget() function creates a new queue or opens an
    existing one
  • msgsnd() places a message on a queue
  • msgrcv() reads a message from a queue
  • msgctl() controls the properties of a queue

6
Semaphores
  • used for resource allocation, not data transfer
  • essentially, an advisory resource locking
    mechanism
  • simple counter, which starts with a number of
    resources available, is decremented when a
    resource is used, and incremented when its
    returned
  • semaphores are manipulated in sets of one or more

7
Semaphore Functions
  • semget() creates or fetches the ID of a semaphore
    set
  • semctl() controls the properties of a semaphore
    set
  • uses the semun union
  • semop() performs operations on semaphores, such
    as decrementing or incrementing them
  • uses the sembuf structure

8
Shared Memory
  • allows multiple processes to share regions of
    memory
  • fastest possible form of IPC
  • shmget() creates or fetches ID of existing shared
    memory segment
  • shmctl() controls the properties of a shared
    memory segment
  • shmat() attaches to a shared memory segment
  • shmdt() detaches from a shared memory segment
  • this does NOT remove it, call to shmctl()
    required for that

9
Shell Tools
  • two shell tools are available for examining and
    removing IPC structures
  • ipcs will list structures the user has read
    access to
  • always check for structures you may have
    inadvertently left behind when testing
  • ipcrm will remove structures the user has
    created or owns, or will remove any for the
    superuser
Write a Comment
User Comments (0)
About PowerShow.com