프로그램 안에서 현재 자신이 백그라운드로 실행 중인지
아니면 포그라운드로 실행 중인지 알 수 있는 방법이 있을까요?
http://kldp.org/node/101010#comment-469389 와 유사하게
표준입력(0)을 isatty 함수로 채크하면 되는군요.
How can a process detect if it's running in the background?http://www.faqs.org/faqs/unix-faq/faq/part3/section-7.html
aero님 답변감사합니다.
int main() { if (isatty(0) ) printf("foreground\n"); else printf("background\n"); }
$ ./test $ ./test &
이렇게 테스트를 해봤는데 둘다 포그라운드가 찍히네요 테스트를 잘 못한 걸까요...
isatty 로 하려면 백그라운드로 도는 프로그램이 쉘과 완전히 단절되어야 할것 같습니다. & 한 후 터미널을 종료한다던가 해야겠네요.
emerge moneyhttp://wiki.kldp.org/wiki.php/GentooInstallSimple - 명령어도 몇개 안되요~http://xenosi.de/
https://xenosi.de/
텍스트 포맷에 대한 자세한 정보
<code>
<blockcode>
<apache>
<applescript>
<autoconf>
<awk>
<bash>
<c>
<cpp>
<css>
<diff>
<drupal5>
<drupal6>
<gdb>
<html>
<html5>
<java>
<javascript>
<ldif>
<lua>
<make>
<mysql>
<perl>
<perl6>
<php>
<pgsql>
<proftpd>
<python>
<reg>
<spec>
<ruby>
<foo>
[foo]
이렇게 해보세요.
http://kldp.org/node/101010#comment-469389 와 유사하게
표준입력(0)을 isatty 함수로 채크하면 되는군요.
How can a process detect if it's running in the background?
http://www.faqs.org/faqs/unix-faq/faq/part3/section-7.html
aero님
aero님 답변감사합니다.
int main()
{
if (isatty(0) ) printf("foreground\n");
else
printf("background\n");
}
$ ./test
$ ./test &
이렇게 테스트를 해봤는데 둘다 포그라운드가 찍히네요
테스트를 잘 못한 걸까요...
isatty 로 하려면
isatty 로 하려면 백그라운드로 도는 프로그램이 쉘과 완전히 단절되어야 할것 같습니다.
& 한 후 터미널을 종료한다던가 해야겠네요.
emerge money
http://wiki.kldp.org/wiki.php/GentooInstallSimple - 명령어도 몇개 안되요~
http://xenosi.de/
https://xenosi.de/
댓글 달기