I have a program reading from standard input in a while
loop. I need to run it in the background, even after I close the console. If the name of the program is prog
, how can I do that?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
You'll have to provide stdin redirected from some source other than the keyboard (which disappears when you log out), but
nohup prog < inputfile > outputfile 2> errorlogfile
should do the trick.
回答2:
When I started with UNIX 24 years ago I had the same question.
If you are a newbie then what you are looking for is tmux
: Here you can start a program that reads from STDIN, log out, log back in some time later, and continue.
Otherwise nohup
is the correct answer.
回答3:
You might be looking for screen
$ screen
$ prog < inputfile
# CTRL-A, CTRL-D to detach from the screen tty
# Log out or close console; log back in, or start another console later.
# To re-attach to the screen tty:
$ screen -r