I want to run a 3 go routine on different process. Upon research I found that I need to use runtime.GOMAXPROCS(). But even after using runtime.GOMAXPROCS(), all routine runs on same process. How can I make it run on different process. Below is the code and output. Here is the link to goplayground
func main() {
runtime.GOMAXPROCS(4)
fmt.Printf("Number of CPU %d
",runtime.NumCPU())
fmt.Printf("Process id of main %d
",os.Getpid())
for i:=0 ;i<3; i++{
go printAndSleep(i)
}
time.Sleep(time.Second * 100)
}
func printAndSleep(i int){
for {
fmt.Printf("Process id of %d go routine %d
",i,os.Getpid())
time.Sleep(time.Second * 2)
}
}
Output :
Number of CPU 8
Process id of main 16874
Process id of 0 go routine 16874
Process id of 2 go routine 16874
Process id of 1 go routine 16874
Process id of 0 go routine 16874
Process id of 1 go routine 16874
Process id of 2 go routine 16874
Process id of 0 go routine 16874
Process id of 1 go routine 16874
Process id of 2 go routine 16874
Process id of 2 go routine 16874
Process id of 0 go routine 16874
Process id of 1 go routine 16874
Here you can see all the routine runs on same process even though I have used GOMAXPROCS . Why is that? Am I using it wrong