简体   繁体   中英

Obtain the Master Port Name of a Pseudo Terminal

How do you get the master port name when I create a Pseudo Terminal? I know I can use ptsname() to obtain the slave port name but what about the master?

int fdm, fds;
char slave_port_name[256];
int open_res = openpty(&fdm, &fds, slave_port_name, NULL, NULL);

system("ls -l /dev/");
printf("Master Port Name: %s, file descriptor: %d\n", ??? How to get master portname?, fdm);
printf("Slave Port Name: %s, file descriptor: %d\n", slave_port_name, fds);

You can't - there is no name for the master in the open_pt interface (there is a name for the masters in BSD style pty, however). You can't "open" the master device a second time, but you can dup the fd and pass it around if you need to (why do you need to, though?)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM