Spawn vs fork

This is part of the Semicolon&Sons Code Diary - consisting of lessons learned on the job. You're in the unix category.

Last Updated: 2022-05-26

Imagine you are running a Ruby program.

Basically fork is used when you want a child process that will run code within this same ruby program. However spawn is used if you want to run another external program. It's the equivalent of running fork followed by exec.

The original caller process can choose to wait or continue concurrently without waiting.