This is a creation in Article, where the information may have evolved or changed.
昨天搞了个文件共享的小程序,遇见了意见蛋疼的事,就是启动之后终端不能关闭,不然程序也会随着关闭.
My workaround:
Nohup./httpserver &
nohup This command can run the program in the background, by the way 1> and 2> to the standard output and standard error redirection to the file, so that the program crashes when there is a record to check, both and the program's log is best to separate, mixed together no way to determine the priorities:
Nohup./server 1> server.out 2> server.err
The process starts by recording its own PID:
if PID := Syscall.Getpid(); PID != 1 {Ioutil.WriteFile("Server.pid", []byte(StrConv.Itoa(PID)), 0777)defer OS.Remove("Server.pid")}
while listening for the kill signal from the system, do some finishing work when receiving the kill signal:
signal.Notify(sigTERM, syscall.SIGTERM)
This allows you to close the service process with the KILL command:
kill `cat game_server.pid`