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); }
相关文章推荐
- UNIX-LINUX编程实践教程->第五章->实例代码注解->setecho.c
- UNIX-LINUX编程实践教程->第五章->实例代码注解->echostate.c
- 《Unix-Linux编程实践教程》读书笔记(四)
- Unix/Linux 编程实践教程 第7章 笔记(1)
- Unix-Linux编程实践教程——第十三章
- UNIX-LINUX编程实践教程->第二章->实例代码注解->cp1
- Unix-Linux编程实践教程——第三章
- 《Unix-Linux编程实践教程》读书笔记(十)
- UNIX-LINUX编程实践教程->第八章->实例代码注解->写一个简单的shell
- Unix-Linux编程实践教程——第六章
- Unix-Linux编程实践教程——第八章
- Unix-Linux编程实践教程——第十四章
- Unix/linux 编程实践教程 ---------- 服务器-客户端编程
- Unix/Linux 编程实践教程 第6章 笔记
- Unix-Linux编程实践教程——第二章
- Unix-Linux编程实践教程——第四章
- Linux下more命令C语言实现实践 (Unix-Linux编程实践教程)
- Unix-Linux编程实践教程——第十章
- UNIX-LINUX编程实践教程->第四章->实例代码注解->pwd1
- UNIX-LINUX编程实践教程->第三章->实例代码注解->ls2