一般将程序在后台运行可以使用命令nohup命令,像这样:
nohup ./server>> log_server.log 2>&1
如果 你用less log_server.log会发现不能实时刷新,大约要达到4K才写入一次,
具体可参考https://aicode.cc/wei-shen-me-ni-de-ming-ling-xing-cheng-xu-mei-you.html,
要实时输出可以使用stdbuf命令。
nohup stdbuf -i0 -o0 -e0 ./server >> log_server.log 2>&1
这样就可以将日志实时输出到日志文件中。
参考:https://unix.stackexchange.com/questions/25372/turn-off-buffering-in-pipe