Skip to content

open file descriptors of the shell aren't inherited by processes launched by the shell, unlike bash or zsh #747

Description

@adavies42

compare ksh:

$ echo $KSH_VERSION                                                                                                                                                                                                                                                                                                                                                        
Version AJM 93u+m/1.0.8 2024-01-01
$ exec {fd}<.profile
$ echo $fd
11
$ ksh
$ lsof -ap$$ -d11                                                                                                                                                                                                                                                                                                                                                          
$ 

and bash:

$ echo $BASH_VERSION
5.2.26(1)-release
$ exec {fd}<.profile
$ echo $fd
10
$ bash
$ lsof -ap$$ -d10
COMMAND   PID    USER   FD   TYPE DEVICE SIZE/OFF        NODE NAME
bash    42373 adavies   10r   REG    1,4        0 12988192685 /Users/adavies/.profile
$ 

zsh behaves like bash

this breaks patterns like

$ exec {fd}<.profile                                                                                                                                                                                                                                                                                                                                                       
$ flock $fd
flock: data error: Bad file descriptor
$ 

since flock(1) doesn't see that file descriptor as open

strace shows ksh launches processes with vfork(2), while bash uses clone(2); maybe this is the cause of the difference?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions