随笔分类 -  Linux系统编程实践

Understanding Unix/Linux Programming-事件驱动编程:编写一个视频游戏
摘要:通过这个例子呢,作者希望我们了解更多的Unix系统服务,一些基本的原则,和操作系统的设计技术 考虑两人参与的星际旅行视频游戏,车给你需创立行星、流星、飞船和其他物体的影像,并使他们移动。每个物体有自己的移动速度、方向、动力和其他一些属性。物体之间相互作用,可能碰撞。 游戏需要同时响应用户输入。玩家通 阅读全文

posted @ 2016-03-23 13:12 H.D 阅读(432) 评论(0) 推荐(0)

Understanding Unix/Linux Programming-用户程序play_again4.c
摘要:1 /* play_again4.c 2 * When no is input , restore the tty settings 3 */ 4 5 #include 6 #include 7 #include 8 #include 9 #include 10 #include 11 12 #define ASK "D... 阅读全文

posted @ 2016-03-23 09:39 H.D 阅读(286) 评论(0) 推荐(0)

Understanding Unix/Linux Programming-信号与play_again4.c的准备知识
摘要:Ctrl-C终止当前运行的程序,这个中断由一个称为信号的内核机制产生。信号是一个简单而重要的概念,下面将探讨信号的基本概念。 终端驱动程序在这里起到了相应的作用: 当然未必一定是Ctrl-C作为中断的控制字符,这是可以更改驱动设置的。 信号是由单个词组成的消息。绿灯、停止标牌、裁判手势等都是信号,而 阅读全文

posted @ 2016-03-22 09:07 H.D 阅读(335) 评论(0) 推荐(0)

Understanding Unix/Linux Programming-用户程序:play_again3
摘要:这里使用到了非阻塞输入: 怎么解释非阻塞输入与阻塞输入? 书上解释: 当调用getchar或者read从文件描述符读取输入时,这些调用通常会等待输入,这叫做阻塞输入(block input)。在play_again的例子中,对于getchar的调用使得程序一直等待用户的输入,知道用户输入一个字符。程 阅读全文

posted @ 2016-03-18 15:28 H.D 阅读(349) 评论(0) 推荐(0)

Understanding Unix/Linux Programming-用户程序:play_again2
摘要:1 /* play_again1.c 2 * purpuse: ask if user wants another play 3 * better : instant response without echo 4 * returns: 0 -> yes , 1 -> no 5 */ 6 7 #include 8 #include 9 #include... 阅读全文

posted @ 2016-03-18 14:25 H.D 阅读(190) 评论(0) 推荐(0)

Understanding Unix/Linux Programming-用户程序:play_again1
摘要:1 /* play_again1.c 2 * purpuse: ask if user wants another play 3 * better : instant response without echo 4 * returns: 0 -> yes , 1 -> no 5 */ 6 7 #include 8 #include 9 #include... 阅读全文

posted @ 2016-03-17 10:58 H.D 阅读(276) 评论(0) 推荐(0)

Understanding Unix/Linux Programming-用户程序:play_again0
摘要:1 /* play_again0.c 2 * purpuse: ask if user wants another play 3 * returns: 0 -> yes , 1 -> no 4 */ 5 6 #include 7 #include 8 #include 9 10 #define QUESTION "Do you want anot... 阅读全文

posted @ 2016-03-17 10:57 H.D 阅读(254) 评论(0) 推荐(0)

Understanding Unix/Linux Programming-终端控制和信号
摘要:终端驱动程序的模式: 先通过简短的转换程序来深入理解设备驱动程序的细节: 使用tr命令能够达到同样的效果,但是tr的GNU版本具有输入缓冲,以上是一个不带缓冲的具体例子。这个程序中,rotate程序是和终端驱动器交换数据的,而终端驱动器从键盘输入数据并且从屏幕输出数据。 规范模式:缓冲和编辑 使用默 阅读全文

posted @ 2016-03-17 10:17 H.D 阅读(358) 评论(0) 推荐(0)

Understanding Unix/Linux Programming-文件、设备和流
摘要:每个设备文件都支持系统调用 ioctl: 实际上,任何数据的源或者目的地都被Unix视为文件来处理,基本的系统调用既支持磁盘文件,也适用于设备文件。它们的区别体现在对于连接的操作上。磁盘文件的文件描述符包含对缓冲属性和扩展属性的定义代码;而终端的文件描述符包含编辑、回显、字符转换和其他操作的定义代码 阅读全文

posted @ 2016-03-16 21:19 H.D 阅读(335) 评论(0) 推荐(0)

Understanding Unix/Linux Programming-stty指令练习
摘要:先来看一个简单的练习程序: 以上是程序编译后运行的效果啦,可以看到在输入hello之后敲击回车后才运行了该程序,也就是说,在终端中输入的字符实际上是被缓冲的。 另外,回车键本身被识别为换行了,也由该程序识别了,这也与终端的设置有关。 tty驱动程序包含很多对数据的操作: 编写终端驱动程序:关于系统调 阅读全文

posted @ 2016-03-16 11:16 H.D 阅读(243) 评论(0) 推荐(0)

Understanding Unix/Linux Programming-设备文件与磁盘连接的概念
摘要:我只是书本的搬运工,具体见《Unix/Linux编程实践教程》 Linux/Unix中,文件包含数据,具有属性,通过目录中的名字被标识,可以从文件中读写数据,而这种方法也被广泛应用于设备。 对于Unix而言,声卡、终端、鼠标和磁盘文件是同一种对象,每个设备都被当作是文件,都具有文件名、inode节点 阅读全文

posted @ 2016-03-14 22:15 H.D 阅读(495) 评论(0) 推荐(0)

Understanding Unix/Linux Programming-pwd指令练习
摘要:系统调用的意义: mkdir:创建目录 rmdir:删除空目录 unlink:删除一个链接 link:创建一个新链接 rename:重命名或者删除一个链接 chdir:切换所调用进程的当前目录 1 #include <sys/types.h> 2 #include <sys/stat.h> 3 #i 阅读全文

posted @ 2016-03-10 19:54 H.D 阅读(226) 评论(0) 推荐(0)

Understanding Unix/Linux Programming-ls指令练习二
摘要:完善ls练习一的功能: 排序,使用qsort 分栏,计算宽度和行数 文件“.”的显示需要由-a选项来选择 详细信息的显示,-l选项 将stat结构体中的st_mode——16位二进制数转换成10位的字符串 15-12:type 11:suid 10:sgid 9:sticky 8-6:user 5- 阅读全文

posted @ 2016-03-09 12:58 H.D 阅读(236) 评论(0) 推荐(0)

Understanding Unix/Linux Programming-ls指令练习一
摘要:1 #include <stdio.h> 2 #include <sys/types.h> 3 #include <dirent.h> 4 5 void do_ls(char[]); 6 7 main(int ac , char * av[]) 8 { 9 if(ac == 1 ) 10 { 11 阅读全文

posted @ 2016-03-08 09:35 H.D 阅读(155) 评论(0) 推荐(0)

Understanding Unix/Linux Programming-who指令练习
摘要:1 /*Apply a Buffer trick in who3.c*/ 2 3 #include <stdio.h> 4 #include <stdlib.h> 5 #include <utmp.h> 6 #include <fcntl.h> 7 #include <unistd.h> 8 #in 阅读全文

posted @ 2016-03-07 22:48 H.D 阅读(231) 评论(0) 推荐(0)

Understanding Unix/Linux Programming-cp指令练习
摘要:1 #include <stdio.h> 2 3 #include <unistd.h> 4 5 #include <fcntl.h> 6 7 #include <stdlib.h> 8 9 10 11 #define BUFFERSIZE 4096 12 13 #define COPYMODE 0 阅读全文

posted @ 2016-03-07 09:52 H.D 阅读(275) 评论(0) 推荐(0)

导航