Skip to content

Instantly share code, notes, and snippets.

@ormaaj
Created February 3, 2026 08:47
Show Gist options
  • Select an option

  • Save ormaaj/bdf4de8c997fbe8c5ad8e2ded10624c4 to your computer and use it in GitHub Desktop.

Select an option

Save ormaaj/bdf4de8c997fbe8c5ad8e2ded10624c4 to your computer and use it in GitHub Desktop.
Demonstrate a small optimization avoiding a pointless open().
ormaajbox /home/gentoo # ( echo; set +m; export BASH_COMPAT=50; { strace --always-show-pid --seccomp-bpf -DDYyyqqqe t=%desc bash -O lastpipe -O extglob "/proc/$((++BASH_COMPAT,BASHPID))/fd/9"; } 9<<-\_EOF 2> >(sed -E '/pipe2/q;d'; cat); wait )
x=<(:) x=${x##*/} command eval exec '{d[0]}<&"$x" {d[1]}>"/proc/self/fd/${x}"'
lsfd -p "$BASHPID" -Q "${| printf -v REPLY 'FD == %b || ' "${d[@]}\c"; }" -o +flags
:
_EOF
7135<bash> pipe2([3<pipe:[35912]>, 4<pipe:[35912]>], 0) = 0
7135<bash> fcntl(63<pipe:[37935]>, F_GETFD) = 0
7135<bash> fcntl(62, F_GETFD) = -1 EBADF (Bad file descriptor)
7135<bash> dup2(3<pipe:[35912]>, 62) = 62<pipe:[35912]>
7135<bash> close(3<pipe:[35912]>) = 0
7135<bash> lseek(255</tmp/sh-thd.A4fWCs>(deleted), -86, SEEK_CUR) = 79
7135<bash> close(4<pipe:[35912]>) = 0
7135<bash> fcntl(62<pipe:[35912]>, F_DUPFD, 10) = 10<pipe:[35912]>
7135<bash> fcntl(62<pipe:[35912]>, F_GETFD) = 0
7135<bash> openat(AT_FDCWD</home/gentoo>, "/proc/self/fd/62", O_WRONLY|O_CREAT|O_TRUNC, 0666) = 3<pipe:[35912]>
7135<bash> --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=7140<bash>, si_uid=0, si_status=0, si_utime=0, si_stime=0} ---
7135<bash> fcntl(3<pipe:[35912]>, F_DUPFD, 10) = 11<pipe:[35912]>
7135<bash> close(3<pipe:[35912]>) = 0
7135<bash> close(62<pipe:[35912]>) = 0
7135<bash> mmap(NULL, 528384, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f34efe23000
7135<bash> read(255</tmp/sh-thd.A4fWCs>(deleted), "lsfd -p \"$BASHPID\" -Q \"${| print"..., 165) = 86
7135<bash> newfstatat(AT_FDCWD</home/gentoo>, ".", {st_mode=S_IFDIR|0755, st_size=300, ...}, 0) = 0
7135<bash> newfstatat(AT_FDCWD</home/gentoo>, "/usr/local/sbin/lsfd", 0x7ffff1107180, 0) = -1 ENOENT (No such file or directory)
7135<bash> newfstatat(AT_FDCWD</home/gentoo>, "/usr/local/bin/lsfd", 0x7ffff1107180, 0) = -1 ENOENT (No such file or directory)
7135<bash> newfstatat(AT_FDCWD</home/gentoo>, "/usr/bin/lsfd", {st_mode=S_IFREG|0755, st_size=220432, ...}, 0) = 0
7135<bash> newfstatat(AT_FDCWD</home/gentoo>, "/usr/bin/lsfd", {st_mode=S_IFREG|0755, st_size=220432, ...}, 0) = 0
7135<bash> newfstatat(AT_FDCWD</home/gentoo>, "/usr/bin/lsfd", {st_mode=S_IFREG|0755, st_size=220432, ...}, 0) = 0
7135<bash> lseek(255</tmp/sh-thd.A4fWCs>(deleted), -2, SEEK_CUR) = 163
COMMAND PID USER ASSOC XMODE TYPE SOURCE MNTID INODE NAME FLAGS
bash 7135 root 10 r----- FIFO pipefs 17 35912 pipe:[35912]
bash 7135 root 11 -w---- FIFO pipefs 17 35912 pipe:[35912] wronly,largefile
7135<bash> ioctl(2<pipe:[37935]>, TIOCGWINSZ, 0x7ffff11072c0) = -1 ENOTTY (Inappropriate ioctl for device)
7135<bash> --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=7141, si_uid=0, si_status=0, si_utime=0, si_stime=0} ---
7135<bash> read(255</tmp/sh-thd.A4fWCs>(deleted), ":\n", 165) = 2
7135<bash> read(255</tmp/sh-thd.A4fWCs>(deleted), "", 165) = 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment