Linux 系统编程:终端操作与进程间通信
1. 创建伪终端(PTY)程序
1.1 准备工作
要创建一个 PTY 程序,你需要以下工具:
- GCC 编译器
- Make 工具
- screen 程序
1.2 编写代码
将以下代码写入一个名为 my-pty.c 的文件中:
#define _XOPEN_SOURCE 600
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <string.h>
#include <unistd.h>
int main(void)
{
char rxbuf[1];
char txbuf[3];
int master; /* for the pts master fd */
int c; /* to catch read's return value */
master = posix_openpt(O_RDWR);
grantpt(master);
unlockpt(master);
printf("Slave: %s\n", ptsname(master));
while(1) /* main loop */
{
/* read from the master file descriptor */
c = read(master,
超级会员免费看
订阅专栏 解锁全文
1260

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



