Home Resources Forum Advertise Contact

Go Back   Webmaster Forums > Operating Sysems and Hardware > On Unix/Linux OS

On Unix/Linux OS Discuss about the Linux OS and its variants regarding updates, issues and troubleshooting techniques here.

Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old 8th January 2007, 09:50 AM
hassen1 hassen1 is offline
WD Addict Poster
 
Join Date: 29th October 2006
Posts: 2,603
Send a message via Yahoo to hassen1
Default How can a process detect if it's running in the background?

First of all: do you want to know if you're running in the
background, or if you're running interactively? If you're
deciding whether or not you should print prompts and the like,
that's probably a better criterion. Check if standard input
is a terminal:

sh: if [ -t 0 ]; then ... fi
C: if(isatty(0)) { ... }

In general, you can't tell if you're running in the background.
The fundamental problem is that different shells and different
versions of UNIX have different notions of what "foreground" and
"background" mean - and on the most common type of system with a
better-defined notion of what they mean, programs can be moved
arbitrarily between foreground and background!

UNIX systems without job control typically put a process into the
background by ignoring SIGINT and SIGQUIT and redirecting the
standard input to "/dev/null"; this is done by the shell.

Shells that support job control, on UNIX systems that support job
control, put a process into the background by giving it a process
group ID different from the process group to which the terminal
belongs. They move it back into the foreground by setting the
terminal's process group ID to that of the process. Shells that
do *not* support job control, on UNIX systems that support job
control, typically do what shells do on systems that don't
support job control.
Reply With Quote
Reply



Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT -4. The time now is 06:03 AM.


Powered by vBulletin
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC6
vB Ad Management by =RedTyger=