#include <termios.h> int tcflush(int fileDescriptor, int queue);
tcflush
is called by a process to flush all input
that has received but not yet been read by a terminal, or all output
written but not transmitted to the terminal. Flushed data are discarded
and cannot be retrieved.
fileDescriptor
queue
queue
are defined in <termios.h>
and can be any of the following:
TCIFLUSH
TCOFLUSH
TCIOFLUSH
tcflush
returns a 0
if successful and a -1
if unsuccessful.
If tcflush
is called from a background process with a
file descriptor that refers to the controlling terminal for the
process, a SIGTTOU
signal may be generated. This will cause
the function call to be unsuccessful, returning a -1
and
setting errno
to EINTR
. If SIGTTOU
is blocked, the function call proceeds normally.
tcflush
to
flush both the input and output queues of a terminal:
#include <sys/types.h>> #include <termios.h> #include <unistd.h> #include <stdio.h> #include <stdlib.h> main() { int ttyDevice = STDOUT_FILENO; /* Make sure file descriptor is for a TTY device. */ if ( ! isatty(ttyDevice) ) { printf("Not a TTY device.n"); return(EXIT_FAILURE); } /* Flush both the input and output queues. */ else { if (tcflush(ttyDevice, TCIOFLUSH) == 0) printf("The input and output queues have been flushed.n"); else perror("tcflush error"); } return(EXIT_SUCCESS); }
tcdrain
, tcflow
Copyright (c) 1998 SAS Institute Inc. Cary, NC, USA. All rights reserved.