duanping1632 2017-10-27 11:33
浏览 100

runtime.GOMAXPROCS无法按预期工作

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.

  • 写回答

1条回答 默认 最新

  • dstd2129 2017-10-27 11:39
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害