C/C++ 进程如何知道它是否在后台运行? [英] How can a C/C++ process know if it runs in background?
本文介绍了C/C++ 进程如何知道它是否在后台运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的进程中有一个方法,只有在进程不在后台时才应该运行该方法.如何动态测试当前进程是否在后台?谢谢
I have a method in my process that should be run only if the process is not in background. How can I dynamically test if the current process is in background ? Thanks
推荐答案
查看 Unix 常见问题:进程如何检测它是否在后台运行?
Check out Unix FAQ: How can a process detect if it's running in the background?
一般答案是:你无法判断你是否在后台运行.
General answer is: You can't tell if you're running in the background.
但你可以检查标准输入是否是终端:if(isatty(0)) { ... }
But you can check if stdin is a terminal: if(isatty(0)) { ... }
这篇关于C/C++ 进程如何知道它是否在后台运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文