13.07.2015 Views

An Operating Systems Vade Mecum

An Operating Systems Vade Mecum

An Operating Systems Vade Mecum

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

304 Co-operating Processes Chapter 9DestroyPort(port number). This call deallocates the port. <strong>An</strong>y process that hasthe port open finds it closed and might be notified by a virtual interrupt.A process that wishes to use the Finger service executes the following program.1 const2 FingerPortNumber = 79;34 var5 MyPortNumber : PortNumber;6 MyPortDescriptor, FingerPortDescriptor : PortDescriptor;7 FingerMessage : string;89 begin10 { Initialization }11 MyPortNumber := CreatePort(new);12 MyPortDescriptor := OpenPort(MyPortNumber,read);13 FingerPortDescriptor := OpenPort(FingerPortNumber,write);14 { Make request }15 Write(FingerPortDescriptor,MyPortNumber);16 { Get <strong>An</strong>swer }17 Read(MyPortDescriptor,FingerMessage);18 { Finalization }19 ClosePort(FingerPortDescriptor);20 ClosePort(MyPortDescriptor);21 DestroyPort(MyPortNumber);22 endFigure 9.7 shows the ports and the messages that are sent. The calling process, A, firstmakes a new port that it will use to get the answer (line 11). It opens this port (line 12) tolisten for the answer and opens the well-known Finger port (line 13) to make its request.The request itself (line 15) includes just the ‘‘return envelope,’’ that is, A’s port number.The Finger server will read this request, open A’s port for writing, write the answer there,and then close that port. A waits (line 17) for the answer to arrive and then releases bothits port descriptors (lines 19−20) and its personal port (line 21). The port manager in thekernel makes sure that only owners destroy ports.How are well-known port numbers different from port files? The main differenceis that port numbers are more widely accessible. <strong>An</strong>y process that knows its number canopen a well-known port, whereas only those processes that have access to the port filemay open its port. The port file can be protected just as can any other file. The increasedaccessibility of port numbers is especially important if the computer is part of a looselycoupled network, such as Arpanet, which connects hundreds of computers across NorthAmerica and Europe. The managers at an installation may not want to make the filestructures accessible to outside processes, and the operating system may have no way toopen a file or to search a directory on behalf of a process outside the machine. Nonetheless,many operating systems allow distant processes to open connections on well-knownports. For security, the server (like Finger in our example) could be informed wheneverits port is opened and could reject the connection.Our Finger example shows two shortcomings of well-known ports. First, the portthat A created for the answer is public in the sense that any other process might haveguessed its name, opened it, and written to it. Second, knowing a port number is not thesame as having a port descriptor; the latter must be derived from the former by an Open-Port call. We can limit the dissemination of ports and unify numbers with descriptors byintroducing port capabilities.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!