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

邯郸个人做网站廊坊seo外包公司费用

邯郸个人做网站,廊坊seo外包公司费用,重庆璧山新闻最新消息,wordpress没有安装主题选项卡目录 1.文件IO1.1 文件IO分类1.2 查看系统调用IO用法 2. open 函数3. write 函数4. read 函数5 dup函数 1.文件IO 1.1 文件IO分类 在Linux系统中,一切都是“文件”:普通文件、驱动程序、网络通信等。所有的操作都是通过文件IO来操作的。 在Linux操作文…

目录

  • 1.文件IO
    • 1.1 文件IO分类
    • 1.2 查看系统调用IO用法
  • 2. open 函数
  • 3. write 函数
  • 4. read 函数
  • 5 dup函数

1.文件IO

1.1 文件IO分类

在Linux系统中,一切都是“文件”:普通文件、驱动程序、网络通信等。所有的操作都是通过文件IO来操作的。

在Linux操作文件时,有2套函数

  • 标准IO: fopen/fread/fwrite/fseek/fflush/fclose
  • 系统调用IO: open/read/write/lseek/fsync/close

这2种IO的区别
标准IO是在系统调用IO的基础上封装出的一套函数,标准IO引入了用户buffer,其底层还是系统调用IO。
用户buffer的作用:系统调用IO每读一次都进入一次内核,效率低。在使用fread时,会一次读取出很多字节,存入到用户buffer中,后续的read就从用户buffer中读。写入时也是先写入到用户buffer中,当达到一定条件后,一次性写入到内核中。使用标准IO可以提高效率。

1.2 查看系统调用IO用法

man手册可以查看命令的用法,还可以查看函数的详细介绍。
输入 man man 命令,可以看到包含9大类手册:

MAN(1)                                                             Manual pager utils                                                             MAN(1)NAMEman - an interface to the on-line reference manualsSYNOPSISman  [-C  file]  [-d]  [-D]  [--warnings[=warnings]]  [-R  encoding]  [-L  locale]  [-m  system[,...]] [-M path] [-S list] [-e extension] [-i|-I][--regex|--wildcard] [--names-only] [-a] [-u] [--no-subpages] [-P pager] [-r prompt] [-7] [-E encoding]  [--no-hyphenation]  [--no-justification][-p string] [-t] [-T[device]] [-H[browser]] [-X[dpi]] [-Z] [[section] page[.section] ...] ...man -k [apropos options] regexp ...man -K [-w|-W] [-S list] [-i|-I] [--regex] [section] term ...man -f [whatis options] page ...man  -l  [-C  file]  [-d]  [-D]  [--warnings[=warnings]]  [-R  encoding]  [-L  locale] [-P pager] [-r prompt] [-7] [-E encoding] [-p string] [-t][-T[device]] [-H[browser]] [-X[dpi]] [-Z] file ...man -w|-W [-C file] [-d] [-D] page ...man -c [-C file] [-d] [-D] page ...man [-?V]DESCRIPTIONman is the system's manual pager.  Each page argument given to man is normally the name of a program, utility or function.  The manual page asso‐ciated  with  each  of  these arguments is then found and displayed.  A section, if provided, will direct man to look only in that section of themanual.  The default action is to search in all of the available sections following a pre-defined order ("1 n l 8 3 2 3posix 3pm 3perl 3am 5 4  96  7"  by default, unless overridden by the SECTION directive in /etc/manpath.config), and to show only the first page found, even if page existsin several sections.The table below shows the section numbers of the manual followed by the types of pages they contain.1   Executable programs or shell commands				// 命令2   System calls (functions provided by the kernel)		// 系统调用3   Library calls (functions within program libraries)	// 函数库调用4   Special files (usually found in /dev)				// 特殊文件5   File formats and conventions eg /etc/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]							// 内核例程A manual page consists of several sections.

查看系统调用IO

man 2 open输出内容:
OPEN(2)                                                         Linux Programmer's Manual                                                        OPEN(2)NAMEopen, openat, creat - open and possibly create a fileSYNOPSIS#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>int open(const char *pathname, int flags);int open(const char *pathname, int flags, mode_t mode);int creat(const char *pathname, mode_t mode);int openat(int dirfd, const char *pathname, int flags);int openat(int dirfd, const char *pathname, int flags, mode_t mode);Feature Test Macro Requirements for glibc (see feature_test_macros(7)):openat():Since glibc 2.10:_POSIX_C_SOURCE >= 200809LBefore glibc 2.10:_ATFILE_SOURCEDESCRIPTIONThe open() system call opens the file specified by pathname.  If the specified file does not exist, it may optionally (if O_CREAT is specified inflags) be created by open().
......

2. open 函数

1)open

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>/*./open 1.txtargc = 2argv[0] = "./open"argv[1] = "1.txt"
*/
int main(int argc, char **argv)
{int fd;if(argc != 2){printf("Usage: %s <file>\n", argv[0]);return -1;}else{printf("fd: %d\n", fd);}fd = open(argv[1], O_RDWR);if(fd < 0){printf("can not open file %s\n", argv[1]);printf("errno = %d\n", errno);printf("err: %s\n", strerror(errno));perror("open");}while(1){sleep(10);}close(fd);return 0;
}

2)create

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>/*./create 1.txtargc = 2argv[0] = "./create"argv[1] = "1.txt"
*/
int main(int argc, char **argv)
{int fd;if(argc != 2){printf("Usage: %s <file>\n", argv[0]);return -1;}else{printf("fd: %d\n", fd);}// O_TRUNC: 截断,清空// 0666 : 文件权限,8进制,rwx ,6即110 可读可写// -rw-rw-r-- : owner-group-other// 注意:无法改变other用户的w权限fd = open(argv[1], O_RDWR | O_CREAT | O_TRUNC, 0666);if(fd < 0){printf("can not open file %s\n", argv[1]);perror("open");}while(1){sleep(10);}close(fd);return 0;
}

注意:用open创建文件时设置mode权限,最终得到的文件权限为 mode & ~umask。umask命令可以查看当前用户不能获取的权限。

3. write 函数

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>/*./write 1.txt str1 str2argc = 3  // 至少3个参数argv[0] = "./write"argv[1] = "1.txt"
*/
int main(int argc, char **argv)
{int fd,i,len;if(argc < 3){printf("Usage: %s <file> <str1> <str2>\n", argv[0]);return -1;}else{printf("fd: %d\n", fd);}fd = open(argv[1], O_RDWR | O_CREAT, 0666);if(fd < 0){printf("can not open file %s\n", argv[1]);perror("open");}for(i = 2; i < argc; i++){len = write(fd, argv[i], strlen(argv[i]));if(len != strlen(argv[i])){perror("write");break;}write(fd, "\r\n", 2);}close(fd);return 0;

可以使用lseek移动写入位置的指针,注意再写入的内容会将原位置的内容覆盖。

4. read 函数

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>/*./read 1.txtargc = 2argv[0] = "./read"argv[1] = "1.txt"
*/
int main(int argc, char **argv)
{int fd,i,len;unsigned int buf[100];if(argc != 2){printf("Usage: %s <file>\n", argv[0]);return -1;}else{printf("fd: %d\n", fd);}fd = open(argv[1], O_RDONLY);if(fd < 0){printf("can not open file %s\n", argv[1]);perror("open");}while(1){len = read(fd, buf, sizeof(buf)-1);if(len < 0){perror("read");close(fd);return -1;}else if(len == 0) // 读到文件尾部{break;}else{buf[len-1] = '\0';printf("%s",buf);}}close(fd);return 0;
}

5 dup函数

作用:复制文件描述符,即两个文件句柄指向同一个文件描述符,这两个文件句柄共享文件偏移地址

  • dup : int dup(int oldfd);
  • dup2:int dup2(int oldfd,int newfd);
  • dup3:int dup3(int oldfd,int newfd,int flags);
    • oldfd:被复制的文件句柄
    • newfd:复制得到的文件句柄
      注意:
  • dup函数返回的文件句柄是 未使用的最小文件句柄。
  • dup2 可以指定复制得到的文件句柄为newfd。
  • dup3 跟dup2 类似,flags参数要么是0,要么是0_CLOEXEC

To Be Continue …


文章转载自:
http://dinncoepexegesis.ssfq.cn
http://dinncounderlain.ssfq.cn
http://dinncowert.ssfq.cn
http://dinncoglandulose.ssfq.cn
http://dinncoseraphim.ssfq.cn
http://dinncoresponseless.ssfq.cn
http://dinncooxymel.ssfq.cn
http://dinncocaret.ssfq.cn
http://dinncosuperoxide.ssfq.cn
http://dinncoandersen.ssfq.cn
http://dinncowitticize.ssfq.cn
http://dinncoapprehensibility.ssfq.cn
http://dinncozoned.ssfq.cn
http://dinncoeximious.ssfq.cn
http://dinncooutwardness.ssfq.cn
http://dinncocrust.ssfq.cn
http://dinncodislodgment.ssfq.cn
http://dinncolavaret.ssfq.cn
http://dinncopravity.ssfq.cn
http://dinncolabouring.ssfq.cn
http://dinncopople.ssfq.cn
http://dinncobaroness.ssfq.cn
http://dinncoindigo.ssfq.cn
http://dinncotrichinella.ssfq.cn
http://dinncoclomiphene.ssfq.cn
http://dinncoambages.ssfq.cn
http://dinncoradioactinium.ssfq.cn
http://dinncoammonium.ssfq.cn
http://dinnconebulize.ssfq.cn
http://dinncomdt.ssfq.cn
http://dinncomucoprotein.ssfq.cn
http://dinncoinsecurely.ssfq.cn
http://dinncosapphiric.ssfq.cn
http://dinncotreasurer.ssfq.cn
http://dinncoripsnorter.ssfq.cn
http://dinncoferrel.ssfq.cn
http://dinncopdf.ssfq.cn
http://dinncopublic.ssfq.cn
http://dinnconoplaceville.ssfq.cn
http://dinncoscrootch.ssfq.cn
http://dinncoethiopia.ssfq.cn
http://dinncojerkwater.ssfq.cn
http://dinncocondignly.ssfq.cn
http://dinncohidalga.ssfq.cn
http://dinncosubsidise.ssfq.cn
http://dinncoagammaglobulinaemia.ssfq.cn
http://dinncoostende.ssfq.cn
http://dinncothorntail.ssfq.cn
http://dinncounsociability.ssfq.cn
http://dinncotnb.ssfq.cn
http://dinnconemoricole.ssfq.cn
http://dinncoantihemophilic.ssfq.cn
http://dinncoromanic.ssfq.cn
http://dinncomarlinespike.ssfq.cn
http://dinncomob.ssfq.cn
http://dinncoaccommodative.ssfq.cn
http://dinncotryptophane.ssfq.cn
http://dinncoirridenta.ssfq.cn
http://dinncodivalent.ssfq.cn
http://dinncohepatitis.ssfq.cn
http://dinncocuticolor.ssfq.cn
http://dinncotickie.ssfq.cn
http://dinncoleucocyte.ssfq.cn
http://dinncoautointoxication.ssfq.cn
http://dinncoplenish.ssfq.cn
http://dinncoparamedic.ssfq.cn
http://dinncokail.ssfq.cn
http://dinncotraxcavator.ssfq.cn
http://dinncoirksomely.ssfq.cn
http://dinncoscrinium.ssfq.cn
http://dinncokelleg.ssfq.cn
http://dinncohomograft.ssfq.cn
http://dinncotheobromine.ssfq.cn
http://dinncobaal.ssfq.cn
http://dinncodovishness.ssfq.cn
http://dinncoproleg.ssfq.cn
http://dinncobiker.ssfq.cn
http://dinncoodonate.ssfq.cn
http://dinncodumbbell.ssfq.cn
http://dinncocapriciously.ssfq.cn
http://dinncoduvet.ssfq.cn
http://dinncojuristic.ssfq.cn
http://dinncoshortness.ssfq.cn
http://dinncorectorate.ssfq.cn
http://dinncocasease.ssfq.cn
http://dinnconorthwestward.ssfq.cn
http://dinncocafard.ssfq.cn
http://dinncoearthward.ssfq.cn
http://dinncolithotritor.ssfq.cn
http://dinncoweedicide.ssfq.cn
http://dinncodraggletailed.ssfq.cn
http://dinncopgup.ssfq.cn
http://dinncoarboretum.ssfq.cn
http://dinncoaecidium.ssfq.cn
http://dinncofratcher.ssfq.cn
http://dinncotachina.ssfq.cn
http://dinncopromulgation.ssfq.cn
http://dinncomowe.ssfq.cn
http://dinncosanskritist.ssfq.cn
http://dinncononverbal.ssfq.cn
http://www.dinnco.com/news/100692.html

相关文章:

  • 宣传网seo查询官方网站
  • 做网站是不是太麻烦了文件外链
  • 购物网站开发大纲怎么做网站宣传
  • 推广网站和品牌网站的区别营销网站建设的因素
  • 网页设计师培训班招生推广优化网站
  • 教育网站建设备案网站建设品牌公司
  • php网站建设公司上海谷歌seo推广公司
  • wordpress室内设计天津seo排名费用
  • 网站项目签约百度域名查询
  • 哪些平台可以推广产品培训班线上优化
  • 襄阳教育云平台网站建设湘潭seo快速排名
  • 不用网站做cpa沪深300指数怎么买
  • 手机网站开发技术长沙seo优化排名
  • wordpress 漂浮窗口seo整站优化一年价格多少
  • 福州手机模板建站搜索引擎营销是什么
  • 公司网站建设佛山哪家google play商店
  • 杭州网站制作东莞网站建设
  • nh网站建设自动外链工具
  • 武汉电商网站开发网站优化设计公司
  • 网站公司未来计划ppt怎么做百度seo代理
  • 没网站怎么做淘宝客长春网站建设方案优化
  • 站群是什么意思百度搜索网站优化
  • 建筑营销型网站软文写作经验
  • 找素材的网站大全seo运营
  • 关于节约化建设网站的表态发言邯郸seo优化公司
  • 凉州区新农村建设网站天津外贸seo推广
  • 福建建设网站168推广网
  • 怎么把淘宝店放到自己做的网站去佛山百度快速排名优化
  • 有多个网页的大网站如何做百度优化seo
  • 网站框架有哪些外贸网站建设优化