SIGPIPE signal happens on attempt to write to closed or broken pipe. In this situation process is terminated and returns error code 141. It is possible to simulate this signal by creating not correct output redirection. Example below shows that tee command output to stdout and file a.a and returns 0:
# echo -n ladydebug.com | md5sum | tee a.a 879d2a4d3a6005aac57bde52958fa079 – # echo $? 0 # cat a.a 879d2a4d3a6005aac57bde52958fa079 -0 |
The next example reveals situation when tee command makes to valid redirection and returns exit code 141:
# echo -n ladydebug.com | md5sum | tee >(echo ladydebug.com) ladydebug.com 879d2a4d3a6005aac57bde52958fa079 – # echo $? 141 |
Repeat previous command with tracing system calls and signals to find out when SIGPIPE signal is generated:
# echo -n ladydebug.com | md5sum | strace -e trace=openat tee >(echo ladydebug.com) ladydebug.com strace: Exit of unknown pid 498716 ignored openat(AT_FDCWD, “./glibc-hwcaps/x86-64-v4/libc.so.6”, O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory) openat(AT_FDCWD, “./glibc-hwcaps/x86-64-v3/libc.so.6”, O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory) openat(AT_FDCWD, “./glibc-hwcaps/x86-64-v2/libc.so.6”, O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory) openat(AT_FDCWD, “./tls/haswell/avx512_1/x86_64/libc.so.6”, O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory) openat(AT_FDCWD, “./tls/haswell/avx512_1/libc.so.6”, O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory) openat(AT_FDCWD, “./tls/haswell/x86_64/libc.so.6”, O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory) openat(AT_FDCWD, “./tls/haswell/libc.so.6”, O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory) openat(AT_FDCWD, “./tls/avx512_1/x86_64/libc.so.6”, O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory) openat(AT_FDCWD, “./tls/avx512_1/libc.so.6”, O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory) openat(AT_FDCWD, “./tls/x86_64/libc.so.6”, O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory) openat(AT_FDCWD, “./tls/libc.so.6”, O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory) openat(AT_FDCWD, “./haswell/avx512_1/x86_64/libc.so.6”, O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory) openat(AT_FDCWD, “./haswell/avx512_1/libc.so.6”, O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory) openat(AT_FDCWD, “./haswell/x86_64/libc.so.6”, O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory) openat(AT_FDCWD, “./haswell/libc.so.6”, O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory) openat(AT_FDCWD, “./avx512_1/x86_64/libc.so.6”, O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory) openat(AT_FDCWD, “./avx512_1/libc.so.6”, O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory) openat(AT_FDCWD, “./x86_64/libc.so.6”, O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory) openat(AT_FDCWD, “./libc.so.6”, O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory) openat(AT_FDCWD, “/etc/ld.so.cache”, O_RDONLY|O_CLOEXEC) = 3 openat(AT_FDCWD, “/lib/x86_64-linux-gnu/libc.so.6”, O_RDONLY|O_CLOEXEC) = 3 openat(AT_FDCWD, “/usr/lib/locale/locale-archive”, O_RDONLY|O_CLOEXEC) = 3 openat(AT_FDCWD, “/usr/share/locale/locale.alias”, O_RDONLY|O_CLOEXEC) = 3 openat(AT_FDCWD, “/usr/share/locale/en_US.UTF-8/LC_MESSAGES/coreutils.mo”, O_RDONLY) = -1 ENOENT (No such file or directory) openat(AT_FDCWD, “/usr/share/locale/en_US.utf8/LC_MESSAGES/coreutils.mo”, O_RDONLY) = -1 ENOENT (No such file or directory) openat(AT_FDCWD, “/usr/share/locale/en_US/LC_MESSAGES/coreutils.mo”, O_RDONLY) = -1 ENOENT (No such file or directory) openat(AT_FDCWD, “/usr/share/locale/en.UTF-8/LC_MESSAGES/coreutils.mo”, O_RDONLY) = -1 ENOENT (No such file or directory) openat(AT_FDCWD, “/usr/share/locale/en.utf8/LC_MESSAGES/coreutils.mo”, O_RDONLY) = -1 ENOENT (No such file or directory) openat(AT_FDCWD, “/usr/share/locale/en/LC_MESSAGES/coreutils.mo”, O_RDONLY) = -1 ENOENT (No such file or directory) openat(AT_FDCWD, “/usr/share/locale-langpack/en_US.UTF-8/LC_MESSAGES/coreutils.mo”, O_RDONLY) = -1 ENOENT (No such file or directory) openat(AT_FDCWD, “/usr/share/locale-langpack/en_US.utf8/LC_MESSAGES/coreutils.mo”, O_RDONLY) = -1 ENOENT (No such file or directory) openat(AT_FDCWD, “/usr/share/locale-langpack/en_US/LC_MESSAGES/coreutils.mo”, O_RDONLY) = -1 ENOENT (No such file or directory) openat(AT_FDCWD, “/usr/share/locale-langpack/en.UTF-8/LC_MESSAGES/coreutils.mo”, O_RDONLY) = -1 ENOENT (No such file or directory) openat(AT_FDCWD, “/usr/share/locale-langpack/en.utf8/LC_MESSAGES/coreutils.mo”, O_RDONLY) = -1 ENOENT (No such file or directory) openat(AT_FDCWD, “/usr/share/locale-langpack/en/LC_MESSAGES/coreutils.mo”, O_RDONLY) = -1 ENOENT (No such file or directory) openat(AT_FDCWD, “/dev/fd/63”, O_WRONLY|O_CREAT|O_TRUNC, 0666) = 3 879d2a4d3a6005aac57bde52958fa079 – — SIGPIPE {si_signo=SIGPIPE, si_code=SI_USER, si_pid=498719, si_uid=0} — +++ killed by SIGPIPE +++ |