Skip to Content
Introducing Erlang, 2nd Edition
book

Introducing Erlang, 2nd Edition

by Simon St. Laurent
March 2017
Beginner
212 pages
4h 47m
English
O'Reilly Media, Inc.
Content preview from Introducing Erlang, 2nd Edition

Chapter 8. Playing with Processes

While Erlang is a functional language, Erlang programs are rarely structured around simple functions. Instead, Erlang’s key organizational concept is the process, an independent component (built from functions) that sends and receives messages. Programs are deployed as sets of processes that communicate with each other. This approach makes it much easier to distribute work across multiple processors or computers, and also makes it possible to do things like upgrade programs in place without shutting down the whole system.

But taking advantage of those features means learning how to create (and end) processes, how to send messages among them, and how to apply the power of pattern matching to incoming messages.

The Shell Is a Process

You’ve been working within a single process throughout this book so far, the Erlang shell. None of the previous examples sent or received messages, of course, but the shell is an easy place to send and (for test purposes, at least) receive messages.

The first thing to explore is the process identifier, often called a pid. The easiest pid to get is your own. In the shell you can just run the self() function:

1> self().
<0.36.0>

<0.36.0> is the shell’s representation of a triple, a set of three integers that provide the unique identifier for this process. (You will probably get a different set of numbers when you try it, though.) This group of numbers is guaranteed to be unique within this run of Erlang, but are not ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Erlang Programming

Erlang Programming

Francesco Cesarini, Simon Thompson
Erlang and OTP in Action

Erlang and OTP in Action

Eric Merritt, Richard Carlsson, Martin Logan
Introducing Erlang

Introducing Erlang

Simon St. Laurent

Publisher Resources

ISBN: 9781491973363Errata PageSupplemental Content