tags:

views:

28

answers:

2

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

pty.fork()¶ Fork. Connect the child’s controlling terminal to a pseudo-terminal. Return value is (pid, fd). Note that the child gets pid 0, and the fd is invalid. The parent’s return value is the pid of the child, and fd is a file descriptor connected to the child’s controlling terminal (and also to the child’s standard input and output).

What's does this mean ? Every process has 3 fd (stdin,stdout,stderr). Does this affects these fds now ? will child process won't have any of these fds? I'm confused.--totally.

+1  A: 

"and fd is a file descriptor connected to the child’s controlling terminal" --> The child process will not see any difference, it will be able to access stdin/out normally (I dont know about stderr). The only difference is that on the other side of the "pipe" is not a terminal where an user is reading/typing, but the parent process which can access is by the returned fd.

joni
A: 

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.

lakshmipathi