Linux系统编程:终端操作与进程间通信
一、创建伪终端(PTY)程序
1.1 准备工作
在编写创建PTY的程序之前,需要准备好GCC编译器、Make工具和screen程序。
1.2 编写程序
以下是创建PTY程序的详细步骤及代码:
1. 创建一个名为 my-pty.c 的文件,并定义 _XOPEN_SOURCE ,包含所需的头文件:
#define _XOPEN_SOURCE 600
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <string.h>
#include <unistd.h>
- 开始
main()函数,并定义所需的变量:
int main(void)
{
char rxbuf[1];
char txbuf[3];
int master; /* for the pts master fd */
int c; /* to catch read's return value */
- 使用
posix_openpt()创建PTY设备,获取文件描述符并保
超级会员免费看
订阅专栏 解锁全文
3290

被折叠的 条评论
为什么被折叠?



