问题
Ubuntu Linux: How can one acquire a path that refers to the master side of a
of a pseudo terminal pair?... the slave side is easy... but the master side only seems to exist as an open file descriptor, but seems not possess a valid Linux path.
With respect to the working Linux pseudo terminal example http://www.man7.org/tlpi/code/online/all_files_by_chapter.html#ch64 covered in the last chapter of this very good Liunx API book: http://www.nostarch.com/tlpi
A questions regarding the current state of Linux linux pseudo terminal API. The example mentioned above, redirects the forked/exec'ed program's stdin/stdout/stderr streams as required to the PTY slave...all is happy on that side of the PTY.
But the pseudo terminal master's path that I need to pass as an argument to a multi tabbed terminal emulator process seems not yet to exist.
My question is with regard to creating a named path forthe Master side of the pseudo terminal pair...as best as I can disern, in the example code mentioned above, only the PTY slave side actually has a name, as the PTY Master side is referred only by way of of an open file descriptor... and when I query the master side path by way of a "readlink("/dev/fd/3"...) it returns the PTY master clone path "/dev/ptmx", thus I gather that the PTY Master side may not yet have a path name as of yet? .. I thought I might be needing to create a valid path by calling link().... but link() only takes an existing path, not an open File descriptor as its argument?... so I tried calling link("/dev/ptmx", NewPTM_name) refurning to the PTY cloan device hoping it might create a link to the resulting PTY master side, but that call fails, returning -1.
I would like to then pass this PTY Master side path string argument to the terminal emulator, perhaps by way of it's command line, or in RoxTerm's case possibly DBus...
I realize that many terminal emulator programs have a -e or -x argument that allows one to run a program inside of a terminal window... Unfortunately taking this approach does not tend to leave one with much control of the parent/child process tree... such is requred as this work is in support of a shared memory multiprocessing system.
回答1:
The current state of the Liunx pseudo terminal API does not make it practical to robustly pass a master side Linux PTY path to a terminal emulation program, as the master side of the pseudo terminal interface is only available as an open file descriptor...
.. But the slave side of a PTY interface does possess a path name that one can pass as an argument between programs.. as suggested by n.m,. one can work around this interface limitation of how one would interconnect the stdio of a program to a new tab in a terminal emulation window.... by requesting via DBus that the terminal emulation program create a new (named) terminal tab, and return the associated slave side path as a result of that DBus call..
.. this leads to this follow on question
"How to: C++, DBus call to a terminal emulation program that creates new terminal, return slave PTY"
来源:https://stackoverflow.com/questions/13557522/using-the-linux-pseudo-terminal-api-for-multiple-debug-terminals