linux – Why is go app running as several processes?-ThrowExceptions

Exception or error:

I have a very simple program written in go:

package main

import (
    "fmt"
    "time"
)

func main() {
    fmt.Println("hello")
    time.Sleep(5 * time.Second)
    fmt.Println("good bye")
}

Now I’m building it using “go build .”. When I look at htop to see the application running, it shows me that several processes are being executed on my machine.

htop output

Can someone explain to me why is that happening? I would expect a single goroutine program to run as single process.

How to solve:

Can someone explain to me why is that happening?

Yes. You are either using htop or top with H which shows threads. Your program uses several threads like any Go program (see also Pizza lord’s comment).

Leave a Reply

Your email address will not be published. Required fields are marked *