从主端更改伪tty回显模式 [英] changing pseudo tty echo mode from the master side

查看:58
本文介绍了从主端更改伪tty回显模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在linux上,我在主机端打开了一个伪tty.虽然从属端没有客户端,但伪tty似乎在回响我正在写给他的所有内容,这不是我所期望的.考虑以下代码:

On linux, I am opening a pseudo tty on the master side. While there is no client on the slave side, the pseudo tty seems to be echoing everything I am writing to him, which is not what I am expecting. Consider the folowing code :

int  main(int argc, char * argv[])
{
    int ptyfd;
    int rc;     /* return code */
    char readbuf[3];
    ptyfd = open("/dev/ptmx", O_RDWR | O_NOCTTY);
    die_on_error(ptyfd, "open ptmx");

    /* unlock and print slave name */
    rc = unlockpt(ptyfd);
    die_on_error(rc, "unlockpt");
    printf("Slave pts name : %s\n", ptsname(ptyfd));

    write(ptyfd, "C", 1);
    rc=read(ptyfd, readbuf, 1);
    die_on_error(rc, "read");
    printf("read returned %c\n",readbuf[0]);
    return 0;   
}

当我运行该程序时,我希望read调用能够阻塞,但它会立即返回并且readbuf的内容为C.如何更改此行为?当从属端未打开时,我希望写在主控端的字符消失或变形,以便以后由从属端读取.

When I run this program, I would expect the read call to block, but instead it immediately returns and the readbuf content is C. How can I change this behaviour ? When the slave side is not opened, I would like the character written on the master side to either vanish or be fifoed for later reading by the slave side.

更改主控端属性是正确的方法吗?

Is changing the master side attributes the right way to do it ?

推荐答案

我认为主端不是tty,但显然是tty,因此您可以调用 tcgettattr 之类的东西tcsetattr ,并抑制回声.

I thought the master side was not a tty, but apparently it is, so you can call things like tcgettattr and tcsetattr, and suppress the echo.

这篇关于从主端更改伪tty回显模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆