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

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

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

评论 (0)

取消