list /proc/self/fd
without allocating pty:
$ docker run testopenfd ls -l /proc/self/fd/
ls: /proc/self/fd/3: cannot read link: No such file or directory
total 0
lr-x------ 1 root root 64 Apr 9 16:14 0 -> /dev/null
l-wx------ 1 root root 64 Apr 9 16:14 1 -> pipe:[621697]
l-wx------ 1 root root 64 Apr 9 16:14 2 -> pipe:[621698]
lr-x------ 1 root root 64 Apr 9 16:14 3
list proc/self/fd
with tty turned on:
$ docker run -t testopenfd ls -l /proc/self/fd/
total 0
lrwx------ 1 root root 64 Apr 9 16:15 0 -> /0
lrwx------ 1 root root 64 Apr 9 16:15 1 -> /0
lrwx------ 1 root root 64 Apr 9 16:15 2 -> /0
ls: /proc/self/fd/3: cannot read link: No such file or directory
lr-x------ 1 root root 64 Apr 9 16:15 3
Run openfds
when no pty allocated (tries to write to pipe):
$ docker run testopenfd
Error on open: open /proc/self/fd/1: permission denied
Can't write, err = invalid argument
Run openfds
when tty turned on:
$ docker run -ti testopenfd
Hello there
package main
import (
"fmt"
"os"
)
func main () {
// open stdout directly as fd 1
file , err := os .OpenFile ("/proc/self/fd/1" , os .O_APPEND | os .O_WRONLY , 0660 )
if err != nil {
fmt .Printf ("Error on open: %v\n " , err )
}
_ , err = file .WriteString ("Hello there" )
if err != nil {
fmt .Printf ("Can't write, err = %v\n " , err )
}
}