[cs631apue] `ls | more` hangs unless stderr is redirected
kthompso
kthompso at stevens.edu
Tue Oct 11 02:26:16 EDT 2016
I am having an issue trying to run the ls-test file against my ls
implementation.
It keeps hanging and timing out at this command `./ls
~jschauma/apue/ls-test | more`.
# ./ls-test
./ls ~jschauma/apue/ls-test | more
timed out
If I run the command directly from the terminal it acts as expected:
# ./ls ~jschauma/apue/ls-test | more
D
a
a.out
asdasd
b
big
c
file.hole
file.nohole
foo9bar
fooDbar
log
moo
symlink
thisisaratherlongfilenamemuchlongerthanmostoftheothers
The system ls also hangs when output to a pipe inside a shell script.
# ./ls-test
ls ~jschauma/apue/ls-test | more
timed out
But again -- from the terminal directly it works as expected.
The only way I can get it to not hang is to redirect stderr to a file.
# ./ls-test
ls | more
timed out
./ls | more
timed out
ls | more 2>/dev/null
ls
ls-test
ls.c
makefile
tmp
./ls | more 2>/dev/null
ls
ls-test
ls.c
makefile
tmp
And of course `ls-test 2>/dev/null` works as well.
This same approach doesn't work when redirecting stderr to stdout.
# ./ls-test
ls | more 2>&1
timed out
./ls | more 2>&1
timed out
Unless you redirect stdout to a file first -- although that's not
surprising.
# ./ls-test 1>ls.out; cat ls.out
ls | more 2>&1
ls
ls-test
ls.c
ls.out
makefile
tmp
./ls | more 2>&1
ls
ls-test
ls.c
ls.out
makefile
tmp
Here's the system information for the linux-lab machine:
# uname -a
Linux smurf 3.2.0-49-generic #75-Ubuntu SMP Tue Jun 18 17:39:32 UTC 2013
x86_64 x86_64 x86_64 GNU/Linux
Thoughts? Does anyone else's ls handle this test case?
-Kyle
More information about the cs631apue
mailing list