linux 下 编译 后台运行、开机启动 golang 程序

编译
linux 下 编译 后台运行、开机启动 golang 程序
编译

go build test.go
指定输出文件

go build -o mygameserver
修改权限命令

chmod 777 程序名称
后台运行的命令

nohup ./程序名 &
不输出错误信息

nohup ./程序名 >/dev/null 2>&1 &
如果要关闭程序,可以使用命令”ps” 查看后台程序的pid,然后使用“kill 程序pid”命令,关闭程序比如程序名为test,可以用如下命令查询

ps aux|grep test
关掉进程

kill 进程编号
开机启动glang

vi /etc/rc.local

添加
cd gopath
nohup ./main &