I have a code running on a Linux server. Since it takes hours to run, I have to use nohup
to make sure my code is still running in case I loose my connection to the server. Again since I have to wait hours to see the results, I defined a counter to print out the progress of my code (%). If I loose my connection to the server or close the terminal, the only way that I can see the code is still running is using top
. Is there any way that I can see again the output console (message showing the progress)?
我有一个在Linux服务器上运行的代码。由于运行需要数小时,因此我必须使用nohup来确保我的代码仍在运行,以防我失去与服务器的连接。因为我必须等待数小时才能看到结果,所以我定义了一个计数器来打印出代码的进度(%)。如果我断开与服务器的连接或关闭终端,我看到代码仍在运行的唯一方法是使用top。有什么方法可以再次看到输出控制台(显示进度的消息)?
2 个解决方案
#1
7
You can redirect standard output and standard error to a file and look at that file. eg:
您可以将标准输出和标准错误重定向到文件并查看该文件。例如:
nohup command 2>&1 > outputfile &
note default behavior from man page:
注意手册页的默认行为:
If standard output is a terminal, append output to 'nohup.out' if possible, '$HOME/nohup.out' otherwise. If standard error is a terminal, redirect it to standard output
如果标准输出是终端,则在可能的情况下将输出附加到'nohup.out',否则为'$ HOME / nohup.out'。如果标准错误是终端,则将其重定向到标准输出
so really you can just run
所以你真的可以跑了
nohup command &
and then look in nohup.out
然后看看nohup.out
#2
19
You can see the output in real time by running below from another terminal.
您可以通过从另一个终端运行以下来实时查看输出。
tail -f nohup.out
#1
7
You can redirect standard output and standard error to a file and look at that file. eg:
您可以将标准输出和标准错误重定向到文件并查看该文件。例如:
nohup command 2>&1 > outputfile &
note default behavior from man page:
注意手册页的默认行为:
If standard output is a terminal, append output to 'nohup.out' if possible, '$HOME/nohup.out' otherwise. If standard error is a terminal, redirect it to standard output
如果标准输出是终端,则在可能的情况下将输出附加到'nohup.out',否则为'$ HOME / nohup.out'。如果标准错误是终端,则将其重定向到标准输出
so really you can just run
所以你真的可以跑了
nohup command &
and then look in nohup.out
然后看看nohup.out
#2
19
You can see the output in real time by running below from another terminal.
您可以通过从另一个终端运行以下来实时查看输出。
tail -f nohup.out