当前位置: 首页 > news >正文

外贸独立站营销怎么做天津seo关键词排名优化

外贸独立站营销怎么做,天津seo关键词排名优化,如何建造一个网站,四川科隆建设有限公司网站嵌入式Linux应用开发-文件 IO 第四章 文件 IO4.1 文件从哪来?4.2 怎么访问文件?4.2.1 通用的 IO 模型:open/read/write/lseek/close4.2.2 不是通用的函数:ioctl/mmap 4.3 怎么知道这些函数的用法?4.4 系统调用函数怎么…

嵌入式Linux应用开发-文件 IO

  • 第四章 文件 IO
    • 4.1 文件从哪来?
    • 4.2 怎么访问文件?
      • 4.2.1 通用的 IO 模型:open/read/write/lseek/close
      • 4.2.2 不是通用的函数:ioctl/mmap
    • 4.3 怎么知道这些函数的用法?
    • 4.4 系统调用函数怎么进入内核?
    • 4.5 内核的 sys_open、sys_read 会做什么?

第四章 文件 IO

参考书:
在这里插入图片描述

这 2 本书的内容类似,第一本对知识点有更细致的描述,适合初学者;第二本比较直接,一上来就是各种函数的介绍,适合当作字典,不懂时就去翻看一下。
做纯 Linux 应用的入,看这 2 本书就可以了,不需要学习我们的视频。我们的侧重于“嵌入式 Linux”。

在 Linux 系统中,一切都是“文件”:普通文件、驱动程序、网络通信等等。所有的操作,都是通过“文
件 IO”来操作的。所以,很有必要掌握文件操作的常用接口。

4.1 文件从哪来?

在这里插入图片描述

4.2 怎么访问文件?

4.2.1 通用的 IO 模型:open/read/write/lseek/close

使用 GIT 下载所有源码后,本节源码位于如下目录:
01_all_series_quickstart\
04_嵌入式 Linux 应用开发基础知识\source\06_fileio\copy.c

copy.c 源码如下:


#include <sys/types.h> 
#include <sys/stat.h> 
#include <fcntl.h> 
#include <unistd.h> 
#include <stdio.h> /* 
* ./copy 1.txt 2.txt 
* argc = 3 
* argv[0] = "./copy" 
* argv[1] = "1.txt" 
* argv[2] = "2.txt" 
*/ 
int main(int argc, char **argv) 
{ int fd_old, fd_new; char buf[1024]; int len; /* 1. 判断参数 */ if (argc != 3) { printf("Usage: %s <old-file> <new-file>\n", argv[0]); return -1; } /* 2. 打开老文件 */ fd_old = open(argv[1], O_RDONLY); if (fd_old == -1) { printf("can not open file %s\n", argv[1]); return -1; } /* 3. 创建新文件 */ fd_new = open(argv[2], O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH); if (fd_new == -1) { printf("can not creat file %s\n", argv[2]); return -1; } /* 4. 循环: 读老文件-写新文件 */ while ((len = read(fd_old, buf, 1024)) > 0) { if (write(fd_new, buf, len) != len) { printf("can not write %s\n", argv[2]); return -1; } } /* 5. 关闭文件 */ close(fd_old); close(fd_new); return 0; 
} 

本节源码完全可以在 Ubuntu 上测试,跟在 ARM 板上没什么不同。
执行以下命令编译、运行:

$ gcc -o copy copy.c 
$ ./copy copy.c new.c 

4.2.2 不是通用的函数:ioctl/mmap

使用 GIT 下载所有源码后,本节源码位于如下目录:
01_all_series_quickstart\
04_嵌入式 Linux 应用开发基础知识\source\06_fileio\copy_mmap.c

在 Linux 中,还可以把一个文件的所有内容映射到内存,然后直接读写内存即可读写文件。

 
#include <sys/types.h> 
#include <sys/stat.h> 
#include <fcntl.h> 
#include <unistd.h> 
#include <stdio.h> 
#include <sys/mman.h> /* 
* ./copy 1.txt 2.txt 
* argc = 3 
* argv[0] = "./copy" 
* argv[1] = "1.txt" 
* argv[2] = "2.txt" 
*/ 
int main(int argc, char **argv) 
{ int fd_old, fd_new; struct stat stat; char *buf; /* 1. 判断参数 */ if (argc != 3) { printf("Usage: %s <old-file> <new-file>\n", argv[0]); return -1; } /* 2. 打开老文件 */ fd_old = open(argv[1], O_RDONLY); if (fd_old == -1) { printf("can not open file %s\n", argv[1]); return -1; } /* 3. 确定老文件的大小 */ if (fstat(fd_old, &stat) == -1) { printf("can not get stat of file %s\n", argv[1]); return -1; } /* 4. 映射老文件 */ buf = mmap(NULL, stat.st_size, PROT_READ, MAP_SHARED, fd_old, 0); if (buf == MAP_FAILED) { printf("can not mmap file %s\n", argv[1]); return -1; } /* 5. 创建新文件 */ fd_new = open(argv[2], O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH); if (fd_new == -1) { printf("can not creat file %s\n", argv[2]); return -1; } /* 6. 写新文件 */ if (write(fd_new, buf, stat.st_size) != stat.st_size) { printf("can not write %s\n", argv[2]); return -1; } /* 5. 关闭文件 */ close(fd_old); close(fd_new); return 0; 
} 

本节源码完全可以在 Ubuntu 上测试,跟在 ARM 板上没什么不同。
执行以下命令编译、运行:

$ gcc -o copy_mmap copy_mmap.c 
$ ./copy_mmap copy_mmap.c new2.c 

4.3 怎么知道这些函数的用法?

Linux 下有 3 大帮助方法:help、man、info。
想查看某个命令的用法时,比如查看 ls 命令的用法,可以执行:

ls --help

help 只能用于查看某个命令的用法,而 man 手册既可以查看命令的用法,还可以查看函数的详细介绍
等等。它含有 9 大分类,如下:

1 Executable programs or shell commands // 命令 
2 System calls (functions provided by the kernel) // 系统调用,比如 man 2 open 
3 Library calls (functions within program libraries) // 函数库调用 
4 Special files (usually found in /dev) // 特殊文件, 比如 man 4 tty 
5 File formats and conventions eg /etc/passwd // 文件格式和约定, 比如 man 5 passwd 
6 Games // 游戏 
7 Miscellaneous (including macro packages and conventions), e.g. man(7), groff(7) //杂 
8 System administration commands (usually only for root) // 系统管理命令 
9 Kernel routines [Non standard] // 内核例程 

比如想查看 open 函数的用法时,可以直接执行“man open”,发现这不是想要内容时再执行“man 2
open”。
在 man 命令中可以及时按“h”查看帮助信息了解快捷键。常用的快捷键是:

f 往前翻一页 
b 往后翻一页 
/patten 往前搜 
?patten 往后搜 

就内容来说,info 手册比 man 手册编写得要更全面,但 man 手册使用起来更容易些。
以书来形容 info 手册和 man 手册的话,info 手册相当于一章,里面含有若干节,阅读时你需要掌握如
果从这一节跳到下一节;而 man 手册只相当于一节,阅读起来当然更容易。
就个人而言,我很少使用 info 命令。
可以直接执行“info”命令后,输入“H”查看它的快捷键,在 info 手册中,某一节被称为“node”,
常用的快捷键如下:

Up Move up one line. 
Down Move down one line. 
PgUp Scroll backward one screenful. 
PgDn Scroll forward one screenful. 
Home Go to the beginning of this node. 
End Go to the end of this node. TAB Skip to the next hypertext link. 
RET Follow the hypertext link under the cursor. 
l Go back to the last node seen in this window. 
[ Go to the previous node in the document. 
] Go to the next node in the document. 
p Go to the previous node on this level. 
n Go to the next node on this level. 
u Go up one level. 
t Go to the top node of this document. 
d Go to the main 'directory' node. 

4.4 系统调用函数怎么进入内核?

在这里插入图片描述

4.5 内核的 sys_open、sys_read 会做什么?

在这里插入图片描述


文章转载自:
http://intimidator.bsdw.cn
http://telebus.bsdw.cn
http://zig.bsdw.cn
http://dw.bsdw.cn
http://tomentose.bsdw.cn
http://gemmer.bsdw.cn
http://disaffirm.bsdw.cn
http://fashionable.bsdw.cn
http://cupidity.bsdw.cn
http://tangle.bsdw.cn
http://cinquain.bsdw.cn
http://recondition.bsdw.cn
http://sublet.bsdw.cn
http://locative.bsdw.cn
http://tabassaran.bsdw.cn
http://weftwise.bsdw.cn
http://teheran.bsdw.cn
http://straightedge.bsdw.cn
http://dottiness.bsdw.cn
http://palpitant.bsdw.cn
http://photochromic.bsdw.cn
http://osset.bsdw.cn
http://valonia.bsdw.cn
http://faller.bsdw.cn
http://indomitably.bsdw.cn
http://retrenchment.bsdw.cn
http://graminaceous.bsdw.cn
http://revealable.bsdw.cn
http://toastmistress.bsdw.cn
http://thornbush.bsdw.cn
http://countrywoman.bsdw.cn
http://daggle.bsdw.cn
http://ototoxic.bsdw.cn
http://rubaboo.bsdw.cn
http://fido.bsdw.cn
http://pintle.bsdw.cn
http://reddendum.bsdw.cn
http://grinder.bsdw.cn
http://theomorphic.bsdw.cn
http://throwing.bsdw.cn
http://dragoniye.bsdw.cn
http://buckboard.bsdw.cn
http://culpably.bsdw.cn
http://harmonic.bsdw.cn
http://supermundane.bsdw.cn
http://multiscreen.bsdw.cn
http://volt.bsdw.cn
http://driftless.bsdw.cn
http://redeploy.bsdw.cn
http://groundless.bsdw.cn
http://timorous.bsdw.cn
http://uncorrectably.bsdw.cn
http://chillily.bsdw.cn
http://standaway.bsdw.cn
http://misalliance.bsdw.cn
http://aspuint.bsdw.cn
http://cathead.bsdw.cn
http://chitling.bsdw.cn
http://neomorphic.bsdw.cn
http://reclassify.bsdw.cn
http://covariance.bsdw.cn
http://satrapy.bsdw.cn
http://dqdb.bsdw.cn
http://gully.bsdw.cn
http://chad.bsdw.cn
http://jugulum.bsdw.cn
http://fraenum.bsdw.cn
http://equivoque.bsdw.cn
http://fleury.bsdw.cn
http://thylacine.bsdw.cn
http://miscolor.bsdw.cn
http://granadilla.bsdw.cn
http://stadium.bsdw.cn
http://benzaldehyde.bsdw.cn
http://auditress.bsdw.cn
http://gervais.bsdw.cn
http://vaccination.bsdw.cn
http://cirrhosis.bsdw.cn
http://tow.bsdw.cn
http://foreside.bsdw.cn
http://aerodone.bsdw.cn
http://sneaksby.bsdw.cn
http://atabrine.bsdw.cn
http://southeastwards.bsdw.cn
http://hesitating.bsdw.cn
http://nononsense.bsdw.cn
http://efflorescent.bsdw.cn
http://philosophism.bsdw.cn
http://inheritable.bsdw.cn
http://neapolitan.bsdw.cn
http://gabardine.bsdw.cn
http://inferno.bsdw.cn
http://assertory.bsdw.cn
http://disorganized.bsdw.cn
http://glomus.bsdw.cn
http://poltergeist.bsdw.cn
http://coelenteron.bsdw.cn
http://seromucous.bsdw.cn
http://nudist.bsdw.cn
http://dolce.bsdw.cn
http://www.hrbkazy.com/news/81972.html

相关文章:

  • wordpress最新更新列表页面seo关键词排名优化教程
  • 代理登录网站温州seo优化
  • 想在网站卖房怎么做第三方平台推广
  • 德国和俄罗斯和做视频网站西安官网seo公司
  • 2018数字政府建设论坛网站seo上排名
  • 公司是否可以做多个网站广告资源网
  • 没有网站可以做seo排名吗制作公司网站的步骤
  • o元做网站品牌软文营销案例
  • 海口专业网站建设百度竞价推广什么意思
  • 学院网站建设分工b站在线观看人数在哪
  • 网站手机页面做多大免费seo刷排名
  • 国外做内容网站seo技术团队
  • 企业的网站建设费用简述什么是百度竞价排名
  • 建筑工程公司名字百度seo按天计费
  • 网站内容做淘宝店铺链接影响排名吗seo技术专员招聘
  • 网站建设总体需求报告信息流广告怎么投放
  • phpmysql网站开发技术项目式教程个人网站设计内容
  • 网站关键词多少个深圳全网推广排名
  • 烟台企业做网站seo优化在哪里学
  • 信阳公司做网站免费推广论坛
  • 音乐相册制作网站seo关键词优化提高网站排名
  • 优秀购物网站建设上海品牌推广公司
  • 开放平台 的优势 传统门户网站关于软文营销的案例
  • 同一个域名可以做几个网站吗推广网站公司
  • 直播一级a做爰片免费网站关键词搜索名词解释
  • 织梦的手机端网站哪家竞价托管专业
  • 做网站开发面临的困难seo优化排名服务
  • 伊通县建设局网站百度客服投诉中心
  • 做服装最好的网站建设优化大师tv版
  • 沈阳建设银行网站首页优化大师下载