What I encountered is I wrote a sample python script named tt.py
:
import time
while True:
print(123)
time.sleep(0.5)
I run it by python tt.py &
, it will output to terminal 123
on-going. And if I input a character l
after several seconds input s
, the command ls
works fine.
But why, as I know a little bit pseudoterminal: master side and slave side. I thought bash's stdin, stdout, stderr is redirect to slave side. So in my mind, the bash should return command like l123\n123\n...s
not found.
So more general question is how bash know which is output which is input when they point to same file descriptor?
Or where I made a misunderstand in this situation, thanks in advance!
Update:
I know stdin and stdout point to different descripor, but they could point to same one right?
So in my mind, python script's stdout to psuedoterminal's slave side, and terminal display streams in master side. Seems what I can't figure out is how terminal stdin goes to bash's stdin. Isn't it first go master side then go slave side then bash?
If so I thougt things will messed up at master side as it receive both python script's output and terminal's input.