1 .\" This manpage is Copyright (C) 2006 Jens Axboe
2 .\" and Copyright (C) 2006 Michael Kerrisk <mtk.manpages@gmail.com>
4 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
6 .TH TEE 2 2020-06-09 "Linux" "Linux Programmer's Manual"
8 tee \- duplicating pipe content
11 .RI ( libc ", " \-lc )
14 .BR "#define _GNU_SOURCE" " /* See feature_test_macros(7) */"
17 .BI "ssize_t tee(int " fd_in ", int " fd_out ", size_t " len \
18 ", unsigned int " flags );
20 .\" Return type was long before glibc 2.7
22 .\" Example programs http://brick.kernel.dk/snaps
25 .\" add a "tee(in, out1, out2)" system call that duplicates the pages
26 .\" (again, incrementing their reference count, not copying the data) from
27 .\" one pipe to two other pipes.
31 bytes of data from the pipe referred to by the file descriptor
33 to the pipe referred to by the file descriptor
35 It does not consume the data that is duplicated from
37 therefore, that data can be copied by a subsequent
41 is a bit mask that is composed by ORing together
42 zero or more of the following values:
45 Currently has no effect for
51 Do not block on I/O; see
56 Currently has no effect for
58 but may be implemented in the future; see
67 Upon successful completion,
69 returns the number of bytes that were duplicated between the input
71 A return value of 0 means that there was no data to transfer,
72 and it would not make sense to block, because there are no
73 writers connected to the write end of the pipe referred to by
80 is set to indicate the error.
87 or one of the file descriptors had been marked as nonblocking
89 and the operation would block.
95 does not refer to a pipe; or
99 refer to the same pipe.
106 system call first appeared in Linux 2.6.17;
107 library support was added to glibc in version 2.5.
109 This system call is Linux-specific.
113 copies the data between the two pipes.
114 In reality no real data copying takes place though:
117 assigns data to the output by merely grabbing
118 a reference to the input.
120 The example below implements a basic
125 Here is an example of its use:
129 $ \fBdate | ./a.out out.log | cat\fP
130 Tue Oct 28 10:06:00 CET 2014
132 Tue Oct 28 10:06:00 CET 2014
137 .\" SRC BEGIN (tee.c)
148 main(int argc, char *argv[])
154 fprintf(stderr, "Usage: %s <file>\en", argv[0]);
158 fd = open(argv[1], O_WRONLY | O_CREAT | O_TRUNC, 0644);
166 * tee stdin to stdout.
168 len = tee(STDIN_FILENO, STDOUT_FILENO,
169 INT_MAX, SPLICE_F_NONBLOCK);
180 * Consume stdin by splicing it to a file.
183 slen = splice(STDIN_FILENO, NULL, fd, NULL,