How to use pseudo-terminals in Linux with C?

后端 未结 3 2014
青春惊慌失措
青春惊慌失措 2020-12-03 17:42

I\'m trying to figure out how to use pseudo-terminal\'s in linux, essentially I want to create a telnetd clone, something I mentioned in an earlier question.

I under

相关标签:
3条回答
  • 2020-12-03 17:57

    You don't lauch a getty for ptys. The getty is only the "listener" part of the process. For hardwired terminals, each individual terminal-device is "listening" constantly. For telnet, the daemon does the listening part(on a socket), and handles connection request by creating a pty pair, and fork()ing / exec()ing. And indeed: APUE handles ptys very well.

    0 讨论(0)
  • 2020-12-03 18:00

    Advanced Programming in the Unix Environment, 2nd Edition has a superb chapter on the pseudo-terminal layer available in Linux. The best part is the source code which contains a pty driver and very clearly demonstrates how to use the pty interfaces. (The pty program it builds is useful in its own right if you want to drive a terminal-only program programmatically but don't wish to use expect(1).)

    0 讨论(0)
  • 2020-12-03 18:19

    include

    #include <sys/stat.h>
    
    #include <fcntl.h>
    
    #define _XOPEN_SOURCE
    
    #include <stdlib.h>
    
    int main(int argc, char **argv) 
    {
    char *slavename;
    int masterfd;
    masterfd = open("/dev/ptmx", O_RDWR);
    grantpt(masterfd);
    unlockpt(masterfd);
    slavename = ptsname(masterfd);
    ...
    }
    

    I posted simple example of demonstrating pseudo terminal master slave concept. please go through this link to get clear understanding of terminals in Linux http://www.linusakesson.net/programming/tty/

    0 讨论(0)
提交回复
热议问题