self-foregrounding processes (was Re: How does a shell know if it's in the foreground or the background?)

Jonathan I. Kamens jik at athena.mit.edu
Fri May 3 17:53:40 AEST 1991


In article <1991May3.015839.9286 at csc.canberra.edu.au>, rvp at softserver.canberra.edu.au (Rey Paulo) writes:
|> Suppose I have a program which I started as a background
|> process.  After a definite period of time, I want the program to run in the
|> foreground without my intervention.  After doing some job in the foreground,
|> I want the program to sit back in the background and repeat the cycle. Note,
|> that shifting from background to foregorund and background is all done by
|> the program itself.

  The concepts of "foreground" and "background" are tied almost inseparably to
the interaction of a user with a terminal.  It is possible for a program to
put itself into the background, for example by fork()ing and having the parent
process exit.  However, once this happens, it makes no sense to ask how the
process can put itself back into the foreground.  Doing that requires that the
process be able to grab control over the tty it was started on back from
whatever process currently has control of the tty.  That just doesn't happen.

  The only processes that "put themselves into the foreground," i.e. take
control of a tty, are those that start up tty sessions, such as getty,
telnetd, etc., and they just take control of a tty in order to hand it over to
another process.

  What are you going to do if your process brings itself back into the
foreground, and the user who started it has logged out and been replaced by
another user on that tty?  What happens if the process brings itself back into
the foreground when the user is typing his password in on the tty?

-- 
Jonathan Kamens			              USnail:
MIT Project Athena				11 Ashford Terrace
jik at Athena.MIT.EDU				Allston, MA  02134
Office: 617-253-8085			      Home: 617-782-0710



More information about the Comp.unix.questions mailing list