-2

I have a simple go program -

main.go -

package main

import (
    "log"
    "runtime"
    "time"
)

func main() {
    runtime.GOMAXPROCS(1)
    log.Println("running")
    time.Sleep(10 * time.Minute)
}

I build binary like this -

GOOS=linux go build

and run it in a centos machine -

# ./test
2017/10/27 14:20:15 running

I wonder why 2 different cores (1 & 6) are used for this simple program even if GOMAXPROCS is set to 1.

process using 2 cpu cores

Sometimes 3-4 cores are also used.

Any idea about this?

Thank you.

Pavan Kishore
  • 91
  • 2
  • 9

1 Answers1

1

You are running four processes. The kernel schedules those onto cores. GOMAXPROCS has nothing to do with this; it only affects the number of threads for a single process, and only user-level code.

Peter
  • 29,454
  • 5
  • 48
  • 60
  • Thanks for the reply @Peter. But I do not understand how four processes are started. I am executing the binary only once. – Pavan Kishore Nov 02 '17 at 12:38