I have a trivial Python script:
#!/usr/bin/python
import os, sys
sys.stderr.write('I am %s' % os.getpid())
sys.stderr.flush()
print "hello"
sys.stderr.write('I am done')
When I run this script from Bash and redirect the stdout to FIFO:
$ mkfifo fifo
$ /pyscript > fifo
the strange thing is, that before I read from the FIFO:
-
I don’t get the ‘I am ‘ message,
-
I can’t see the script using
ps -ef
-
and using lsof, I can’t see anybody has the fifo open!
Once I do read from the FIFO, the both messages that I’m writing ro stderr appear at once.
What is happening?
The background: I’m writing a test where I create FIFO and write ‘hello’ to it; then I run a test and expect the SUT to not read from it; ie. just ignore the file. I tried to do mkfifo test_fifo; /bin/echo hello > test_fifo &; run_the_test; killall echo
but to my surprise, the echo
process never exists! How should I “clean up” after such test (apart from rm test_fifo
…?