Chapter Contents

Previous

Next
tcdrain

tcdrain



Wait for Output to Drain

Portability: POSIX.1 conforming


SYNOPSIS
DESCRIPTION
RETURN VALUE
EXAMPLE
RELATED FUNCTIONS


SYNOPSIS

#include <termios.h>

int tcdrain(int fileDescriptor);


DESCRIPTION

tcdrain blocks the calling process until all output sent to the terminal device referred to by the file descripter fileDescriptor has been sent. If fileDescriptor refers to the controlling terminal, this function cannot be called from a background process unless the SIGTTOU signal is blocked. By default, tcdrain will return a -1 (unsuccessful) if SIGTTOU is generated.

Note that all terminal output is considered to be sent when it has been transmitted to the OMVS command, even if all the data have not yet been actually displayed.


RETURN VALUE

tcdrain returns a 0 if successful and a -1 if unsuccessful.


EXAMPLE

The following example illustrates the use of tcdrain to block a calling process until all output is sent to a terminal, and then to write an output line to that terminal:

#include <sys/types.h>
#include <termios.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>

main()
{
   int ttyDevice = STDOUT_FILENO; 
   char * lineOut = "Jack be nimble!";

      /* Make sure file descriptor is for a TTY device.            */ 
   if ( ! isatty(ttyDevice) ) {
      printf("Not a TTY device.\n"); 
   return(EXIT_FAILURE);
}
      /* Wait for all data transmission to the terminal to finish  */ 
      /* and then write a line to the terminal.                    */ 
   else { 
      if (tcdrain(ttyDevice) != 0)
         perror("tcdrain error"); 
    else
      write(ttyDevice, lineOut, strlen(lineOut)); 
   }
   return(EXIT_SUCCESS);
}


RELATED FUNCTIONS

tcflow , tcflush


Chapter Contents

Previous

Next

Top of Page

Copyright © 2001 by SAS Institute Inc., Cary, NC, USA. All rights reserved.