L10: Shared Memory Flashcards

1
Q

Shared Memory

Overview

A
  • Allows 2 or more processes to share a given region of memory
  • Fastest form of IPC because there is no copying between a “client” and “server”
  • The trick is synchronizing access
  • Semaphores are used to synchronize shared memory access
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Shared Memory:

Important Functions (4)

A
  • shmat()
    • how a process attaches to shared memory
  • shmdt()
    • process detaches from shared memory
  • shmctl()
    • attempt a command on the shared memory
  • mmap()
    • memory mapped input/output
    • alternative to shared memory
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Shared Memory Functions:

shmat()

  • Full declaration
  • Summary
A

void * shmat( int shmid, void *addr, int flag);

Used by a process to attach to shared memory

Returns a pointer to the shared memory

Leaves memory when the process dies. Potential for memory leak!

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Shared Memory Functions:

shmctl()

  • Full Declaration
  • Summary
A

int shmctl( int shmid, int cmd,

struct shmid_ds *buf );

  • Performs various operations on shared memory
  • A command is specified with “cmd”
  • Returns 0 if ok, -1 on error
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Shared Memory:

Commond commands for

shmctl()

A
  • IPC_STAT
    • fills the “buf” data structure
  • IPC_SET
    • change uid, gid and mode fo the shmid
  • IPC_RMID
    • sets up the shared memory segment to be removed once all processes terminate or dettach from the segment
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Shared Memory Functions:

shmdt()

  • Full Declaration
  • Summary
A

void shmdt( void *addr)

  • Used by a process to detach itself from a shared memory segment
  • Sort of similar to using free() for heap memory
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Shared Memory Functions:

mmap()

A
  • Memory Mapped Input/Output
  • Alternative to shared memory
  • Maps a file on DISK into buffer
  • Contents are non-volatile
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Unix Commands

Dealing with

Shared Memory Segments

A
  • ipcs
    • used for listing shared memory segments
  • ipcrm
    • used to remove shared memory segments
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Shared Memory:

Steps for

Creating Shared Memory

A
  1. Use shmget()
    • to obtain a segment of memory with an ID
  2. Use shmat()
    • to get a pointer to the memory segment
  3. Use shmctl()
    • to set up segment to be removed when processes are done with it
  4. Use the pointer as a pointer to a memory block
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly