pv プロセスの stdin と stdout に対して、read(2)
も write(2)
も呼び出されていません。
$ lsb_release -ir
Distributor ID: Ubuntu
Release: 20.04
$ uname -srm
Linux 5.4.0-37-generic x86_64
$ pv --version
pv 1.6.6 - Copyright 2015 Andrew Wood <andrew.wood@ivarch.com>
$ cat /dev/urandom | pv -rf -t -i 2 >/dev/null 2>output & strace -p $! -e read,write
:
write(2, "0:00:02 [31.7MiB/s]", 19) = 19
write(2, "\r", 1) = 1
write(2, "0:00:04 [33.0MiB/s]", 19) = 19
write(2, "\r", 1) = 1
:
read(2)
や write(2)
に変わる何か(system call)が使われているだろうと推測して、以下を実行してみた所、
$ cat /dev/urandom | pv -rf -t -i 2 >/dev/null 2>output & strace -p $! | grep -E '\([01],'
:
select(1, [0], [], NULL, {tv_sec=0, tv_usec=90000}) = 1 (in [0], left {tv_sec=0, tv_usec=86340})
splice(0, NULL, 1, NULL, 131072, SPLICE_F_MORE) = 131072
:
splice(2)
が使われている事が判りました。
man splice(2)
splice() moves data between two file descriptors without copying between kernel address space and user address space.
pv には splice(2)
を利用しないオプションスイッチがあります。
man pv(1)
-C, --no-splice
Never use splice(2), even if it would normally be possible. The splice(2) system call is a more efficient way of transferring data from or to a pipe than regular read(2) and write(2), but means that the transfer buffer may not be used. This prevents -A and -T from working, so if you want to use -A or -T then you will need to use -C, at the cost of a small loss in transfer efficiency. (This option has no effect on systems where splice(2) is unavailable).
$ cat /dev/urandom | pv -C -rf -t -i 2 >/dev/null 2>output & strace -p $! -e read,write
:
read(0, ...
write(1, ...
read(0, ...
write(1, ...
: