Linux下Golang编译程序在后台运行及开机启动

韩昊杰
2022-08-21 / 11 评论 / 740 阅读 / 正在检测是否收录...

Linux下Golang编译程序在后台运行及开机启动

编译

  1. 需要在项目根目录设置GOPATH为amd64

    set GOPACH=amd64
  2. 设置GOOS为linux

    set GOOS=linux
  3. 指定输出文件名

    go build test.go
  4. 指定输出文件名

    go build -o custom_name
  5. 修改可执行权限

    chmod 777 程序名称
  6. 程序后台运行

    nohup ./custom_name &
  7. 不输出错误信息

    nohup ./custom_name >/dev/null 2>&1 &

关闭程序

  • 查询进程号

    ps aux|grep custom_name
  • 关闭进程

    kill 进程编号
  • 开机启动golang

    vi /etc/rc.local
0

评论 (11)

取消
  1. 头像
    xsuhtbbzmm
    Windows 10 · Google Chrome

    你的文章让我感受到了不一样的视角,非常精彩。 https://www.4006400989.com/qyvideo/92199.html

    回复
  2. 头像
    jfhtrqcbzm
    Windows 10 · Google Chrome

    你的文章内容非常卖力,让人点赞。 https://www.yonboz.com/video/85401.html

    回复
  3. 头像
    mkzlwigere
    Windows 10 · Google Chrome

    你的文章让我感受到了不一样的风景,谢谢分享。 https://www.yonboz.com/video/23561.html

    回复
  4. 头像
    ueqtyrxbxv
    Windows 10 · Google Chrome

    你的文章内容非常专业,让人佩服。 https://www.yonboz.com/video/54081.html

    回复
  5. 头像
    gtjviuuttg
    Windows 10 · Google Chrome

    你的文章总是能给我带来欢乐,谢谢你!http://www.lannadecn.com

    回复
  6. 头像
    xrssrwgtji
    Windows 10 · Google Chrome

    看到你的文章,我仿佛感受到了生活中的美好。http://www.gzhplb.com

    回复
  7. 头像
    jningxpmup
    Windows 10 · Google Chrome

    每次看到你的文章,我都觉得时间过得好快。http://www.shhengqianjs.com

    回复
  8. 头像
    udeppfqbaz
    Windows 10 · Google Chrome

    每次看到你的文章,我都觉得时间过得好快。http://www.shhengqianjs.com

    回复
  9. 头像
    kuviufeqvu
    Windows 10 · Google Chrome

    每次看到你的文章,我都觉得时间过得好快。http://www.shhengqianjs.com

    回复
  10. 头像
    khjvhlwuhg
    Windows 10 · Google Chrome

    看到你的文章,我仿佛感受到了生活中的美好。http://www.letujiaotong.com

    回复
  11. 头像
    yhnlxxvuxo
    Windows 10 · Google Chrome

    你的文章内容非常卖力,让人点赞。http://www.thfc420.com

    回复