4. Ports
4 Ports
This section outlines an example of how to solve the example problem in the previous section
by using a port.
The scenario is illustrated in the following figure:
Figure 4.1: Port Communication4.1 Erlang Program
All communication between Erlang and C must be established by creating the port. The Erlang process that creates a port is said to be the connected process of the port. All communication to and from the port must go through the connected process. If the connected process terminates, the port also terminates (and the external program, if it is written properly).
The port is created using the BIF open_port/2
with {spawn,ExtPrg}
as the first argument. The string ExtPrg
is the name of the external program, including any command lin