一个C / C ++程序怎么能知道,如果它在后台运行? [英] How can a C/C++ process know if it runs in background?

查看:169
本文介绍了一个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.

但你可以检查标准输入是终端:如果(isatty(0)){...}

But you can check if stdin is a terminal: if(isatty(0)) { ... }

这篇关于一个C / C ++程序怎么能知道,如果它在后台运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆