您的位置:首页 > 运维架构 > Linux

Unix-Linux编程实践教程——第五章

2017-10-21 13:20 537 查看

章节概要

本章主要讲解设备编程,设备属性,以及如何设置,其实设备和文件有很多相识之处,因为在linux里所有东西都可以看做文件。

tty、shell、terminal、console

词源上的意思:

- terminal(终端)——指电线的末端

- shell——指乌龟的壳

- tty——是一个奇怪的缩写

- console——一种机柜

在UNIX的术语中,最简单的回答是:

- 终端(terminal)=tty=文本的输入输出环境

- 控制台(console)=物理终端

- shell=命令行解释器

详细情况见终端,Shell,“tty”和控制台(console)有什么区别?

write1.c

/*******************************************************
> File Name: write1.c
> Author: Duke-wei
> Mail: 13540639584@163.com
> Created Time: 2017年10月09日 星期一 10时41分45秒
*******************************************************/
#include<stdio.h>
#include<fcntl.h>
#include<stdlib.h>
#include<string.h>
#include<unistd.h>

int main(int ac,char* av[]){
int fd;
char buf[BUFSIZ];
char rebuf[BUFSIZ];
if(ac!=3){
fprintf(stderr,"usage: write0 yourID ttyname\n");
exit(1);
}
fd = open(av[2],O_WRONLY);
if(fd==-1){
perror(av[2]);
exit(1);
}
strncpy(rebuf,av[1],strlen(av[1]));
while(fgets(buf,BUFSIZ,stdin)!=NULL){
strncpy(rebuf,av[1],strlen(av[1]));
strncat(rebuf,buf,strlen(buf));
if(write(fd,rebuf,strlen(rebuf))==-1)
break;
}
close(fd);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: