CS230 System Programming - PowerPoint PPT Presentation

1 / 12
About This Presentation
Title:

CS230 System Programming

Description:

CS230 System Programming Project #3 : IPC (Interprocess Communication) 1. Specification(1/2) Develop who command using shared memory List IDs of shell ... – PowerPoint PPT presentation

Number of Views:79
Avg rating:3.0/5.0
Slides: 13
Provided by: Jae116
Category:

less

Transcript and Presenter's Notes

Title: CS230 System Programming


1
CS230 System Programming
  • Project 3 IPC
  • (Interprocess Communication)

2
1. Specification(1/2)
  • Develop who command using shared memory
  • List IDs of shell processes the same shell
  • Unlink shared memory semaphore when exit the
    shell
  • You need to think about structure to save
    process pid

3
1. Specification(2/2)
  • Develop built-in command msg using shared
    memory signal
  • msg pid Message
  • Use single shared memory to send and receive
    message
  • Send a signal to receiving shell to consume the
    message
  • Issue semaphore to deal a race condition
  • Do not use busy-waiting policy

4
2. Interprocess Communication
  • IPC communication between processes
  • Shared memory
  • Message queuing
  • Semaphore
  • cf. Socket

5
3. Shared Memory(1/3)
  • Memory space that some processes use together

Process I
Process II
Shared memory
6
3. Shared Memory(2/3)
  • shmget
  • Make shared memory segment
  • Int shmget(key_t key, int size, int shmflg)
  • shmat
  • Get address of shared memory segment
  • Int shmat(int shmid, char shmaddr, int shmflg)

7
3. Shared Memory(3/3)
  • shmdt
  • Unload shared memory segment
  • Be careful with unload because there can be other
    process who is dealing with segment
  • int shmdt(char shmaddr)

8
4. Semaphore (1/4)
  • Certain condition
  • Two processes want to write something on same
    position of shared memory at same time-gt
    collision!
  • Use semaphore to give the permission to only one
    process

9
4. Semaphore(2/4)
  • P() get semaphore to contact critical point
  • V() release semaphore after using critical point

10
4. Semaphore(3/4)
  • semget
  • Create semaphore
  • int semget(key_t key, int nsems, int semflg)
  • semop
  • Get or release semaphrore
  • int semop(int semid, struct sembuf sops,
    unsigned nsops)

11
4. Semaphore(4/4)
  • semctl
  • Control semaphore
  • Int semctl(int semid, int semnum, int cmd, union
    semun arg)

12
5. ipcs, ipcrm
  • Deal IPC control
  • shared memory
  • Semaphore
  • Message queue
  • ipcs show using IPC control
  • Ex ipcs m
  • ipcrm remove IPC control
  • Ex ipcrm M shm_key
Write a Comment
User Comments (0)
About PowerShow.com