[comp.unix.questions] How do I wait for Terminal IO to compleate??

sbanner1@uvicctr.UUCP (03/30/87)

Hello,  I have recently been working on a program that I run in my
.logout just before I do an stty 0 (I have to do the stty 0 because
if I leave stuff running in the background when I logout, UNIX hangs
onto the terminal, and we have about 7 different machines that are
all accessed through the same terminals).  The problem is that this
program writes some stuff out to the screen, then exits, then the
stty kills the terminal after only about half of the stuff has been
written out.  I have been given the suggestion that I could just pause
for a few seconds, but that is klugy, and if I then go to a slower
terminal (I regularly use 9600baud, and 1200baud, but sometimes 300),
I will have to increase the delay, and I want the terminal to become
free for other users as quickly as possible.  I know that there is an
ioctl that will see if there is any pending input, but is there a similar
one for output (I have looked, but I can't find it).  I have tried flushing
the files before I exit, but that doesn't help.   HELP!!!!!

                  Thanks,

                      S. John Banner

UUCP     ...!{uw-beaver,ubc-vision}!uvicctr!sol!sbanner1
BITNET   ccsjb@uvvm
ARPA     sbanner1@sol.UVIC.CDN

#1 1121 Fort St.
Victoria BC.
Canada
V8V 3K9

mouse@mcgill-vision.UUCP (der Mouse) (04/10/87)

In article <245@uvicctr.UUCP>, sbanner1@uvicctr.UUCP (S. John Banner) writes:
> I have been given the suggestion that I could just pause for a few
> seconds, but that is klugy, and if I then go to a slower terminal (I
> regularly use 9600baud, and 1200baud, but sometimes 300), I will have
> to increase the delay, and I want the terminal to become free for
> other users as quickly as possible.

You could look at the baud rate and calculate the delay time.

> I know that there is an ioctl that will see if there is any pending
> input, but is there a similar one for output (I have looked, but I
> can't find it).

You don't say what sort of system you are on.  Presumably it is some
sort of UNIX.  SysV? BSD4.2? BSD4.1? Xenix? what?

There is such an ioctl.  It is one of the less standard ioctls, and I
would expect it only on BSD 4.2 and 4.3 (and derivatives): TIOCOUTQ.

int charstoprint;

ioctl(fd,TIOCOUTQ,&charstoprint);

gives the number of characters queued up (waiting to print) in the
kernel's output buffers for the tty the file descriptor refers to.

I have no idea whether there is anything analagous in any other flavors
of UNIX.

					der Mouse

				(mouse@mcgill-vision.uucp)

mpl@sfsup.UUCP (04/20/87)

In article <740@mcgill-vision.UUCP>, mouse@mcgill-vision.UUCP writes:
> In article <245@uvicctr.UUCP>, sbanner1@uvicctr.UUCP (S. John Banner) writes:
> You could look at the baud rate and calculate the delay time.
> 
> > I know that there is an ioctl that will see if there is any pending
> > input, but is there a similar one for output (I have looked, but I
> > can't find it).
> 
> You don't say what sort of system you are on.  Presumably it is some
> sort of UNIX.  SysV? BSD4.2? BSD4.1? Xenix? what?
> 

AT&T UNIX(Tm - UNIX is a trademark of AT&T Bell Laboratories, etc.) SYS V
has the following (taken from the administraor's refernce manual):

	TCSBRK	Wait for the output to drain.  If arg is 0, then send a
		BREAK.

Mike Lindner
ihnp4!attunix!mpl