1tee(2)                        System Calls Manual                       tee(2)
2
3
4

NAME

6       tee - duplicating pipe content
7

LIBRARY

9       Standard C library (libc, -lc)
10

SYNOPSIS

12       #define _GNU_SOURCE         /* See feature_test_macros(7) */
13       #include <fcntl.h>
14
15       ssize_t tee(int fd_in, int fd_out, size_t len, unsigned int flags);
16

DESCRIPTION

18       tee()  duplicates  up to len bytes of data from the pipe referred to by
19       the file descriptor fd_in to the pipe referred to by the file  descrip‐
20       tor  fd_out.   It  does  not  consume  the data that is duplicated from
21       fd_in; therefore, that data can be copied by a subsequent splice(2).
22
23       flags is a bit mask that is composed by ORing together zero or more  of
24       the following values:
25
26       SPLICE_F_MOVE      Currently has no effect for tee(); see splice(2).
27
28       SPLICE_F_NONBLOCK  Do  not  block on I/O; see splice(2) for further de‐
29                          tails.
30
31       SPLICE_F_MORE      Currently has no effect for tee(), but may be imple‐
32                          mented in the future; see splice(2).
33
34       SPLICE_F_GIFT      Unused for tee(); see vmsplice(2).
35

RETURN VALUE

37       Upon successful completion, tee() returns the number of bytes that were
38       duplicated between the input and output.  A return  value  of  0  means
39       that  there  was  no  data  to transfer, and it would not make sense to
40       block, because there are no writers connected to the write end  of  the
41       pipe referred to by fd_in.
42
43       On error, tee() returns -1 and errno is set to indicate the error.
44

ERRORS

46       EAGAIN SPLICE_F_NONBLOCK  was specified in flags or one of the file de‐
47              scriptors had been marked as nonblocking (O_NONBLOCK),  and  the
48              operation would block.
49
50       EINVAL fd_in  or  fd_out  does not refer to a pipe; or fd_in and fd_out
51              refer to the same pipe.
52
53       ENOMEM Out of memory.
54

STANDARDS

56       Linux.
57

HISTORY

59       Linux 2.6.17, glibc 2.5.
60

NOTES

62       Conceptually, tee() copies the data between the two pipes.  In  reality
63       no  real  data  copying takes place though: under the covers, tee() as‐
64       signs data to the output by merely grabbing a reference to the input.
65

EXAMPLES

67       The example below implements a basic tee(1)  program  using  the  tee()
68       system call.  Here is an example of its use:
69
70           $ date | ./a.out out.log | cat
71           Tue Oct 28 10:06:00 CET 2014
72           $ cat out.log
73           Tue Oct 28 10:06:00 CET 2014
74
75   Program source
76
77       #define _GNU_SOURCE
78       #include <errno.h>
79       #include <fcntl.h>
80       #include <limits.h>
81       #include <stdio.h>