1 / 9

System V IPC Identifiers and Keys

System V IPC Identifiers 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

zahina
Download Presentation

System V IPC Identifiers and Keys

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  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 • aren’t 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 • doesn’t 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 it’s ‘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

More Related