python pty.fork - how does it work

前端 未结 5 1932
执笔经年
执笔经年 2020-12-16 18:46

http://docs.python.org/library/pty.html says -

pty.fork()¶ Fork. Connect the child’s controlling terminal to a pseudo-terminal. Return value is

5条回答
  •  温柔的废话
    2020-12-16 19:14

    Thanks Joni.Here is what i understood.When pty.fork() is invoked. parent process is connected to ptmx master. parent will wait for input from keyboard or data from master.

    child closes its stdin,stdout and stderr. And duplicates slaves stdin,stdout.stderr. now child executed a program (say bc).The program is waiting for input,when you type 1+1--its passed to master (remember both child and slave has some stdin,stdout,stderr) by child/slave. master computes its answer "2" and writes into stdout- since parent is waiting for data from master -it picks up "2" and writes into stdout.

    I came this conclusion after going through few good old c programs on pseudo-terminal :) I don't think python's logic won't be different from them. HTH someone.

提交回复
热议问题