You might be coming from Python, right? ;-)

It has the module named multiprocessing in its stdlib, and this might well explain why you have used this name in the title of your question and why you apparently are having trouble interpreting what @JimB meant by saying

If you need a separate process, you need to exec it yourself

"Multiprocessing" in Python

The thing is, Python's multiprocessing is a quite high-level thing which hides under its hood a whole lot of stuff. When you spawn a multiprocessing.Process and make it run a function, what really happens is this:

  1. The Python interpreter creates another operating system's process (using fork(2) on Unix-like systems or CreateProcess on Windows) and arranges for it to execute a Python interpter, too.

    The crucial point is that you will now have two processes running two Python interpters.

  2. It is arranged for that Python interpterer in the child process to have a way to communicate with the Python interpreter in the parent process.

    This "communication link" necessarily involves some form of IPC @JimB referred to. There is simply no other way to communicate data and actions between separate processes exactly because a commodity contemporary OS provides strict process separation.

  3. When you exchange Python objects between the processes, the two communicating Python interpreters serialize and deserialize them behind your back before sending them over their IPC link and after receiving them from there, correspondingly. This is implemented using the pickle module.

Back to Go

Go does not have any direct solution which would closely match Python's multiprocessing, and I really doubt it could have been sensibly implemented.

The chief reason for this mostly stems from the fact Go is quite more lower level than Python, and hence it does not have the Python's luxury of making sheer assumptions about the types of values it manages, and it also strives to have as few hidden costs in its constructs as possible.

Go also strives to steer clear of "framework-style" approaches to solve problems, and use "library-style" solutions when possible. (A good rundown of the "framework vs library" is given, for instance, here.) Go has everything in its standard library to implement something akin to Python's multiprocessing but there is no ready-made frakework-y solution for this.

So what you could do for this is to roll along these lines:

  1. Use os/exec to run another copy of your own process.

    • Make sure the spawned process "knows" it's started in the special "slave" mode—to act accordingly.
    • Use any form of IPC to communicate with the new process. Exchanging data via the standard I/O streams of the child process is supposedly the simplest way to roll (except when you need to exchange opened files but this is a harder topic, so let's not digress).
  2. Use any suitable package in the encoding/ hierarchy — such as binary, gob, xml — to serialize and deserialize data when exchanging.

    The "go-to" solution is supposedly encoding/gob but encoding/json will also do just fine.

  3. Invent and implement a simple protocol to tell the child process what to do, and with which data, and how to communicate the results back to master.

Does it really worth the trouble?

I would say that no, it doesn't—for a number of reasons:

  • Go has nothing like the dreaded GIL, so there's no need to sidestep it to achieve real parallelism when it is naturally possible.

  • Memory safety is all in your hands, and achieving it is not really that hard when you dutifully obey the principle that what is sent over a channel is now owned by the receiver. In other words, sending values over a channel is also the transfer of ownership of those values.

  • The Go toolchain has integrated race detector, so you may run your test suite with the -race flag and create evaluation builds of your program using go build -race for the same purpose: when a program instrumented in such a way runs, the race detector crashes it as soon as it detects any unsynchronized read/write memory access. The printout resulting from that crash includes explanatory messages on what, and where went wrong, with stack traces.

  • IPC is slow, so the gains may well be offset by the losses.

All-in-all, I see no real reason to separate processes unless you're writing something like an e-mail processing server where this concept comes naturally.

Answer from kostix on Stack Overflow
Top answer
1 of 3
47

You might be coming from Python, right? ;-)

It has the module named multiprocessing in its stdlib, and this might well explain why you have used this name in the title of your question and why you apparently are having trouble interpreting what @JimB meant by saying

If you need a separate process, you need to exec it yourself

"Multiprocessing" in Python

The thing is, Python's multiprocessing is a quite high-level thing which hides under its hood a whole lot of stuff. When you spawn a multiprocessing.Process and make it run a function, what really happens is this:

  1. The Python interpreter creates another operating system's process (using fork(2) on Unix-like systems or CreateProcess on Windows) and arranges for it to execute a Python interpter, too.

    The crucial point is that you will now have two processes running two Python interpters.

  2. It is arranged for that Python interpterer in the child process to have a way to communicate with the Python interpreter in the parent process.

    This "communication link" necessarily involves some form of IPC @JimB referred to. There is simply no other way to communicate data and actions between separate processes exactly because a commodity contemporary OS provides strict process separation.

  3. When you exchange Python objects between the processes, the two communicating Python interpreters serialize and deserialize them behind your back before sending them over their IPC link and after receiving them from there, correspondingly. This is implemented using the pickle module.

Back to Go

Go does not have any direct solution which would closely match Python's multiprocessing, and I really doubt it could have been sensibly implemented.

The chief reason for this mostly stems from the fact Go is quite more lower level than Python, and hence it does not have the Python's luxury of making sheer assumptions about the types of values it manages, and it also strives to have as few hidden costs in its constructs as possible.

Go also strives to steer clear of "framework-style" approaches to solve problems, and use "library-style" solutions when possible. (A good rundown of the "framework vs library" is given, for instance, here.) Go has everything in its standard library to implement something akin to Python's multiprocessing but there is no ready-made frakework-y solution for this.

So what you could do for this is to roll along these lines:

  1. Use os/exec to run another copy of your own process.

    • Make sure the spawned process "knows" it's started in the special "slave" mode—to act accordingly.
    • Use any form of IPC to communicate with the new process. Exchanging data via the standard I/O streams of the child process is supposedly the simplest way to roll (except when you need to exchange opened files but this is a harder topic, so let's not digress).
  2. Use any suitable package in the encoding/ hierarchy — such as binary, gob, xml — to serialize and deserialize data when exchanging.

    The "go-to" solution is supposedly encoding/gob but encoding/json will also do just fine.

  3. Invent and implement a simple protocol to tell the child process what to do, and with which data, and how to communicate the results back to master.

Does it really worth the trouble?

I would say that no, it doesn't—for a number of reasons:

  • Go has nothing like the dreaded GIL, so there's no need to sidestep it to achieve real parallelism when it is naturally possible.

  • Memory safety is all in your hands, and achieving it is not really that hard when you dutifully obey the principle that what is sent over a channel is now owned by the receiver. In other words, sending values over a channel is also the transfer of ownership of those values.

  • The Go toolchain has integrated race detector, so you may run your test suite with the -race flag and create evaluation builds of your program using go build -race for the same purpose: when a program instrumented in such a way runs, the race detector crashes it as soon as it detects any unsynchronized read/write memory access. The printout resulting from that crash includes explanatory messages on what, and where went wrong, with stack traces.

  • IPC is slow, so the gains may well be offset by the losses.

All-in-all, I see no real reason to separate processes unless you're writing something like an e-mail processing server where this concept comes naturally.

2 of 3
0

Channel is used for communicating between goroutines, you shouldn't use it in same goroutine like this code:

sensorData <- string(msg.Payload())
fmt.Println(<-sensorData) //currently not printing anything

If you like to test printing by channel, you can use buffered channel in same goroutine to avoid blocking, like this:

sensorData := make(chan []byte, 1)

Cheers

🌐
Antonz
antonz.org › multi
Native threading and multiprocessing in Go
September 22, 2025 - Exploring unconventional ways to handle concurrency.
People also ask

How does Golang handle concurrency and parallelism differently?
Concurrency in Go focuses on managing multiple tasks at once, while parallelism runs those tasks simultaneously when multiple CPU cores are available. Goroutines make it easy to achieve both depending on your system’s hardware. The Go runtime handles scheduling across cores, so you get better performance without extra setup.
🌐
fullstack.com
fullstack.com › labs › resources › blog › goroutines-in-golang-for-high-performance-concurrency
Golang Goroutines for Optimized Concurrency | FullStack Blog
How do goroutines improve performance in Golang applications?
Goroutines let Go handle thousands of tasks at the same time without putting heavy strain on system resources. They’re lightweight, starting with small stack sizes that grow as needed, and managed directly by the Go runtime. This makes them ideal for applications that process many requests or background jobs while keeping response times fast.
🌐
fullstack.com
fullstack.com › labs › resources › blog › goroutines-in-golang-for-high-performance-concurrency
Golang Goroutines for Optimized Concurrency | FullStack Blog
Why are goroutines better than traditional multithreading?
Unlike traditional threads, goroutines consume far less memory and scale efficiently as your app grows. They’re built directly into Go, so the runtime manages scheduling and resource allocation automatically. This simplifies development and allows you to handle high levels of concurrency with less complexity.
🌐
fullstack.com
fullstack.com › labs › resources › blog › goroutines-in-golang-for-high-performance-concurrency
Golang Goroutines for Optimized Concurrency | FullStack Blog
🌐
GitHub
github.com › spzala19 › Multiprocessing-with-golang
GitHub - spzala19/Multiprocessing-with-golang · GitHub
This little research carried out to know how efficeint the Golang concurrency feature is!
Author   spzala19
🌐
Reddit
reddit.com › r/golang › is it worth using goroutines (or multi-threading in general) when nothing is blocking?
r/golang on Reddit: Is it worth using Goroutines (or multi-threading in general) when nothing is blocking?
December 14, 2023 -

This is more of a computer science question, but for a program that has no blocking operations (e.g. file or network IO), and just needs to churn through some data, is it worth parallelising this? If the work needs to be done either way, does adding Goroutines make it any faster?

Sorry if this is a silly question, I've always seen multithreading as a way to handle totally different lines of execution, rather than just approaching the same line of execution with multiple threads.

🌐
Oxyprogrammer's blog
oxyprogrammer.com › tenets-of-multithreading-in-go-detailed-tutorial
Tenets of Multithreading in GO: Detailed Tutorial
March 14, 2025 - Go began development around 2007-08, a time when chip manufacturers recognized the benefits of using multiple processors to increase computational power, rather than merely boosting the clock speed of single processors. While multithreading existed before this period, its real advantages became apparent with the advent of multiprocessor computers. In this article, we will review the various tools that Go provides for writing robust multiprocessing code.
🌐
Spiral
spiral.dev › blog › understanding-concurrency-and-parallelism-in-golang
Spiral Framework: Understanding Concurrency and Parallelism in Golang
July 13, 2020 - As a general concept, concurrency is widely known and used throughout the Go community. The key to achieving Golang concurrency is using Goroutines - lightweight, low-cost methods or functions that can run concurrently with other methods and functions. Golang offers a specific CSP (Communication Sequential Processes) paradigm in its base, which allows for convenient parallel processing using Goroutines to facilitate concurrent execution in code.
Find elsewhere
🌐
Bytegoblin
bytegoblin.io › blog › multiprocessing-with-goroutines-and-channels-in-go-programming
Multiprocessing With Goroutines And Channels In Go Programming
Multiprocessing with Goroutines and Channels provides a robust framework for performing concurrent operations in Go.
🌐
YouTube
youtube.com › code explainer
Parallelism & Concurrency | Multitasking & Multiprocessing | Thread & Process & Goroutine - YouTube
Question Link : Code linK : WEBSITE LINK : https://codeexplainer.teachcode.in/Play Store Link : https://play.google.com/store/apps/details?id=com.coding.cont...
Published   January 23, 2024
Views   218
🌐
FullStack
fullstack.com › labs › resources › blog › goroutines-in-golang-for-high-performance-concurrency
Golang Goroutines for Optimized Concurrency | FullStack Blog
Golang's multithreading is indeed a game changer; it uses goroutines, which are lightweight threads managed by the Go runtime.
🌐
Pure Storage Blog
blog.purestorage.com › home › concurrent programming case study: comparing python, go, and rust
Concurrent Programming Case Study: Comparing Python, Go, and Rust |
November 16, 2025 - I compared concurrent implementations of this example program written using Python multiprocessing, Go, and Rust. Both Go and Rust produce significantly better requests/sec performance than concurrent Python (3x and 4x faster respectively). Surprisingly, Rust is 30% faster than Go, despite this being the first concurrent Rust program that I have written.
🌐
Madeddu
madeddu.xyz › posts › golang vs python: deep dive into the concurrency
GoLang vs Python: deep dive into the concurrency | madeddu.xyz
January 17, 2018 - On the other hand, a well-written concurrent program might run efficiently in parallel on a multiprocessor2. That property could be important. Let’s talk about how GoLang let your program takes advantage of running in a multiprocessor/multithreaded environment, or, what tools GoLang provides to write concurrent program because it’s not about thread or core: it’s all about routine.
🌐
LinkedIn
linkedin.com › pulse › multithreading-go-routines-golang-breno-machado
Multithreading with Go Routines in Golang
July 8, 2023 - In Golang, Go routines enable us to achieve concurrent execution and effectively utilize multiple threads for efficient processing.
🌐
Packt Publishing
hub.packtpub.com › concurrency-and-parallelism-in-golang-tutorial
How Concurrency and Parallelism works in Golang [Tutorial]
July 6, 2018 - Concurrency and parallelism are two terms often used interchangeably. However, they mean two distinctly different things in Go lang. Let's find out how.
🌐
Medium
medium.com › rungo › achieving-concurrency-in-go-3f84cbf870ca
Achieving concurrency in Go. If I had to choose one great feature of… | by Uday Hiwarale | RunGo | Medium
September 1, 2020 - GOLANG Achieving concurrency in Go If I had to choose one great feature of Go, then it has to be in-built concurrency model. Not only it supports concurrency but makes it better. Go Concurrency Model …
🌐
DigitalOcean
digitalocean.com › community › tutorials › how-to-run-multiple-functions-concurrently-in-go
How To Run Multiple Functions Concurrently in Go | DigitalOcean
January 22, 2022 - To run programs faster, a programmer needs to design their programs to run at the same time. Two features in Go, goroutines and channels, make concurrency ea…
🌐
LinkedIn
linkedin.com › pulse › concurrency-parallelism-golang-ankit-malik
Concurrency & Parallelism in Golang
October 22, 2020 - Go runtime executes all these ... to run in multiprocessor mode then we can set the environment variable GOMAXPROCS parameter of Golang to execute goroutines on multiple processors....
🌐
Go Packages
pkg.go.dev › github.com › peng225 › oval › multiprocess
multiprocess package - github.com/peng225/oval/multiprocess - Go Packages
October 28, 2023 - Common problems companies solve with Go · Stories about how and why companies use Go