Interprocess Communication Mechanisms. IPC Signals Pipes System V IPC.

17
Interprocess Communication Mechanisms

Transcript of Interprocess Communication Mechanisms. IPC Signals Pipes System V IPC.

Page 1: Interprocess Communication Mechanisms. IPC Signals Pipes System V IPC.

Interprocess Communication Mechanisms

Page 2: Interprocess Communication Mechanisms. IPC Signals Pipes System V IPC.

IPC

• Signals

• Pipes

• System V IPC

Page 3: Interprocess Communication Mechanisms. IPC Signals Pipes System V IPC.

Signals

• Signal asynchronous events to one or more processes

• Oldest IPC method used by UNIX

• Intel Box– 1)SIGHUP 2) SIGINT 3) SIGQUIT 4) SIGILL– 5) SIGTRAP 6) SIGIOT 7) SIGBUS 8) SIGFPE 9)

SIGKILL 10) SIGUSR1 11) SIGSEGV 12) SIGUSR2 13) SIGPIPE 14) SIGALR 15)SIGTERM 17) SIGCHLD 18) SIGCONT 19) SIGSTOP 20) SIGTSTP 21) SIGTTIN 22) SIGTTOU 23) SIGURG 24) SIGXCPU 25) SIGXFSZ 26) SIGVTALRM 27) SIGPROF 28) SIGWINCH 29) SIGIO 30) SIGPWR

Page 4: Interprocess Communication Mechanisms. IPC Signals Pipes System V IPC.

Signal

• Processes can ignore most of the signals except SIGSTOP, SIGKILL

• A process can choose to block, handle or allow kernel to handle it

• For example, SIGFPE(floating point exception) : core dump and the exit

Page 5: Interprocess Communication Mechanisms. IPC Signals Pipes System V IPC.

Linux Signals • task_struct

– Pending signals : signal (32 bits)

– A mask of blocked signal : blocked

– sigaction array: address of handling routine or a flag to ignore the signal (modified by system calls)

• Normal process can only send signals to processes with the same uid and gid or to the processes in the same process group

Page 6: Interprocess Communication Mechanisms. IPC Signals Pipes System V IPC.

Signal Handling

• Signals are not presented to the process immediately they are generated., they must wait until the process is running again.

• Every time a process exits from a system call its signal and blocked fields are checked and, if there are any unblocked signals, they can now be delivered

Page 7: Interprocess Communication Mechanisms. IPC Signals Pipes System V IPC.

Signal Handling

• Processes can elect to wait for signals if they wish, they are suspended in state Interruptible until a signal is presented

• The Linux signal processing code looks at the sigaction structure for each of the current unblocked signal

Page 8: Interprocess Communication Mechanisms. IPC Signals Pipes System V IPC.

Pipe

• $ls | pr |lpr

• Linux using two file data structure which point at the same temporary VFS inode (points to a physical page within memory)

• use standard read/write library function

Page 9: Interprocess Communication Mechanisms. IPC Signals Pipes System V IPC.

Pipe

Page 10: Interprocess Communication Mechanisms. IPC Signals Pipes System V IPC.

Named Pipe

• FIFO

• created by mkfifo command

Page 11: Interprocess Communication Mechanisms. IPC Signals Pipes System V IPC.

System V IPC Mechanism

• Message queues, semaphores and shared memory

• UNIX System V in 1983

Page 12: Interprocess Communication Mechanisms. IPC Signals Pipes System V IPC.

Message Queues

• Allow one or more processes to write messages, which will be read by one or more reading processes

• msgque --> msqid_ds

• Linux kernel : wait queue

Page 13: Interprocess Communication Mechanisms. IPC Signals Pipes System V IPC.

Message Queues

Page 14: Interprocess Communication Mechanisms. IPC Signals Pipes System V IPC.

Semaphores

• A semaphore is a location in memory whose value can be tested and set (atomic) by more than one processes

• Can be used to implement critical regions

• To prevent deadlock : sem_undo data structure

Page 15: Interprocess Communication Mechanisms. IPC Signals Pipes System V IPC.

Semaphores

Page 16: Interprocess Communication Mechanisms. IPC Signals Pipes System V IPC.

Shared Memory

• Allow one or more processes to communicate via memory that appears in all of their virtual address space

• shmid_ds data structure

Page 17: Interprocess Communication Mechanisms. IPC Signals Pipes System V IPC.

Shared Memory