How to make a program reading stdin run in backgro

2019-06-09 22:32发布

问题:

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


标签: linux shell