c - 获取伪终端主端口名

标签 c linux serial-port pts

当我创建伪终端时,如何获取主端口名称?我知道我可以使用 ptsname() 来获取从属端口名称,但是主控端口又如何呢?

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);

最佳答案

你不能 - open_pt 接口(interface)中没有 master 的名称(但是,BSD 风格的 pty 中有一个 master 的名称)。您无法再次“打开”主设备,但如果需要,您可以复制 fd 并传递它(但为什么需要这样做?)

关于c - 获取伪终端主端口名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30042950/

相关文章:

c++ - 使用我自己的源目录生成 vs2010 项目文件

linux - 将 vimrc 转换为 Windows

linux - 我想计算在 C 中调用了多少次系统调用

Python套接字服务器和客户端,不断失去连接

c++ - QSerialPort::readLine 在 MS Windows 上无法正常工作

windows - 与Windows XP/win32串口通信的基本示例

php - 通过 PHP 提供 C 程序,无需写入/上传权限

c - C 中的静态成员

c - 写入动态内存

windows - Windows Communication Foundation 的 Linux/Mac OS X 等价物