How to make a program reading stdin run in backgro

2019-06-09 22:17发布

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?

标签: linux shell
3条回答
Emotional °昔
2楼-- · 2019-06-09 22:54

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
查看更多
Deceive 欺骗
3楼-- · 2019-06-09 22:59

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.

查看更多
beautiful°
4楼-- · 2019-06-09 23:00

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.

查看更多
登录 后发表回答