Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
Interprocess Communication<br />
When processes A and B run simultaneously, a situation could arise whereby process A has locked semaphore 0<br />
and wants to lock semaphore 1, but process B has locked semaphore 1 and wants to lock semaphore 0.<br />
Both processes sleep, unable to continue. They are deadlocked and exit only on receipt of a signal.<br />
To avoid deadlock use multiple semaphore operations simultaneously:<br />
struct sembuf psernbuf[2];<br />
psernbuf[0].sem_nurn = 0;<br />
psernbuf[l].sem_nurn = 1;<br />
psernbuf[0].sem_op = -1;<br />
psernbuf[0].sem_op = -1;<br />
semop(semid, psernbuf, 2);<br />
! Undo Structures for Semaphores<br />
Per process<br />
Undo Headers<br />
:<br />
-----<br />
Undo Structures<br />
desc<br />
num<br />
value<br />
desc<br />
num<br />
value<br />
desc<br />
num<br />
value<br />
-----<br />
-----<br />
:<br />
desc<br />
num<br />
value<br />
-----<br />
Each undo structure is an array of triples consisting of:<br />
- a semaphore ID,<br />
- a semaphore number in <strong>the</strong> set identified by ID,<br />
- and an adjustment value.<br />
Sequence of Undo Structures<br />
! After first operation<br />
semaphore id semid<br />
semaphore nurn 0<br />
adjustment 1<br />
! After second operation<br />
seamphore id semid semid<br />
semaphore nurn 0 1<br />
adjustment 1 1<br />
! After third operation<br />
semaphore id semid<br />
semaphore nurn 0<br />
adjustment 1<br />
! After fourth operation<br />
empty<br />
BERKELEY Sockets<br />
The Application Program Interface (API) is <strong>the</strong> interface to a programmer. For UNIX <strong>the</strong>re is Berleley Sockets and<br />
System V Transport Layer Interface (TLI).<br />
Network I/O includes File I/O system calls: open, creat, close, read, write, & lseek<br />
! Network I/O considerations<br />
- client or server?<br />
- connection-oriented or connectionless<br />
- process names are more important in networking<br />
- more parameters for a network connection<br />
- communication protocol record boundaries<br />
- support multiple communication protocols<br />
163