1 .\" This manpage is Copyright (C) 2006 Jens Axboe
2 .\" and Copyright (C) 2006 Michael Kerrisk <mtk.manpages@gmail.com>
4 .\" %%%LICENSE_START(VERBATIM)
5 .\" Permission is granted to make and distribute verbatim copies of this
6 .\" manual provided the copyright notice and this permission notice are
7 .\" preserved on all copies.
9 .\" Permission is granted to copy and distribute modified versions of this
10 .\" manual under the conditions for verbatim copying, provided that the
11 .\" entire resulting derived work is distributed under the terms of a
12 .\" permission notice identical to this one.
14 .\" Since the Linux kernel and libraries are constantly changing, this
15 .\" manual page may be incorrect or out-of-date. The author(s) assume no
16 .\" responsibility for errors or omissions, or for damages resulting from
17 .\" the use of the information contained herein. The author(s) may not
18 .\" have taken the same level of care in the production of this manual,
19 .\" which is licensed free of charge, as they might when working
22 .\" Formatted or processed versions of this manual, if unaccompanied by
23 .\" the source, must acknowledge the copyright and authors of this work.
26 .TH TEE 2 2020-06-09 "Linux" "Linux Programmer's Manual"
28 tee \- duplicating pipe content
31 .BR "#define _GNU_SOURCE" " /* See feature_test_macros(7) */"
34 .BI "ssize_t tee(int " fd_in ", int " fd_out ", size_t " len \
35 ", unsigned int " flags );
37 .\" Return type was long before glibc 2.7
39 .\" Example programs http://brick.kernel.dk/snaps
42 .\" add a "tee(in, out1, out2)" system call that duplicates the pages
43 .\" (again, incrementing their reference count, not copying the data) from
44 .\" one pipe to two other pipes.
48 bytes of data from the pipe referred to by the file descriptor
50 to the pipe referred to by the file descriptor
52 It does not consume the data that is duplicated from
54 therefore, that data can be copied by a subsequent
58 is a bit mask that is composed by ORing together
59 zero or more of the following values:
62 Currently has no effect for
68 Do not block on I/O; see
73 Currently has no effect for
75 but may be implemented in the future; see
84 Upon successful completion,
86 returns the number of bytes that were duplicated between the input
88 A return value of 0 means that there was no data to transfer,
89 and it would not make sense to block, because there are no
90 writers connected to the write end of the pipe referred to by
97 is set to indicate the error.
104 or one of the file descriptors had been marked as nonblocking
106 and the operation would block.
112 does not refer to a pipe; or
116 refer to the same pipe.
123 system call first appeared in Linux 2.6.17;
124 library support was added to glibc in version 2.5.
126 This system call is Linux-specific.
130 copies the data between the two pipes.
131 In reality no real data copying takes place though:
134 assigns data to the output by merely grabbing
135 a reference to the input.
137 The example below implements a basic
142 Here is an example of its use:
146 $ \fBdate |./a.out out.log | cat\fP
147 Tue Oct 28 10:06:00 CET 2014
149 Tue Oct 28 10:06:00 CET 2014
164 main(int argc, char *argv[])
170 fprintf(stderr, "Usage: %s <file>\en", argv[0]);
174 fd = open(argv[1], O_WRONLY | O_CREAT | O_TRUNC, 0644);
182 * tee stdin to stdout.
184 len = tee(STDIN_FILENO, STDOUT_FILENO,
185 INT_MAX, SPLICE_F_NONBLOCK);
197 * Consume stdin by splicing it to a file.
200 slen = splice(STDIN_FILENO, NULL, fd, NULL,