Introducing Concurrency with fork() and wait()

In a UNIX-like OS, processes are traditionally created with the system call fork(). fork() doesn’t create a process out of thin air; instead, it creates a copy of the process that calls it, which will have access to all of the calling process’s state and code. This is for a good reason: even if we’re going to call exec, we need some way to control the behavior of the new process before exec is called. fork() allows us to both create a new process and coordinate its behavior with the rest of our code.

Its signature is simple:

 def fork():Int

fork() takes no arguments and returns an Int. Unlike every other function we’ve discussed, and probably unlike every function you’ve ever written, fork() returns ...

Get Modern Systems Programming with Scala Native now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.