bash 前台程序和后台程序有什么区别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/883463/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What's the difference between a foreground and background program?
提问by omg
I tried to run a program in background mode and foreground mode.
我试图在后台模式和前台模式下运行程序。
While in background mode, it failed to run.
在后台模式下,它无法运行。
But in foreground mode, it succeeded.
但是在前台模式下,它成功了。
So what's the difference between background and foreground mode that might cause this issue?
那么可能导致这个问题的后台模式和前台模式有什么区别呢?
回答by Aaron Digulla
A foreground process has access to the terminal (standard input and output).
前台进程可以访问终端(标准输入和输出)。
You can try to fix the issue by adding <> /dev/nullto the commandline. This will tell the program not to use stdin. Some programs take this into accound and "behave" as soon as you don't give them a terminal anymore.
您可以尝试通过添加<> /dev/null到命令行来解决该问题。这将告诉程序不要使用标准输入。一旦你不再给它们一个终端,一些程序就会考虑到这一点并“表现”。
Another solution is the nohupprogram which does basically the same plus some more things.
另一种解决方案是nohup执行基本相同的程序以及更多功能。
回答by Wayne Hartman
Background processes typically run with little or no user interaction, they interact with the system instead. Forground processes are what the user interacts with. Background processes, unless explicitly ran so, run with non-admin permissions. If you ran it under your user-context, then it would likely have the permissions to do whatever it is the app does.
后台进程通常在很少或没有用户交互的情况下运行,而是与系统交互。前台进程是用户与之交互的进程。后台进程,除非明确运行,否则以非管理员权限运行。如果您在用户上下文中运行它,那么它可能有权执行应用程序所做的任何事情。

