1 / 12

CS230 System Programming

CS230 System Programming. Project #3 : IPC (Interprocess Communication). 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

lark
Download Presentation

CS230 System Programming

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. 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-> 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

More Related