In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
Learn from https://blog.csdn.net/lf_2016/article/details/54587020
System call: the user directly calls the interface exposed by the operating system, which is called the system call.
Man manual, man 2 is to query the system call API
The commonly used API is open close read write lseek fcntl.
Library function call: the interface exposed by the operating system is encapsulated to form a library function, which is provided to the user.
The standard file I / O operation is the library function call, man manual, man 3 is the query library function interface.
Common standard library function fopen fread fwrite
In fact, the library function is a layer of encapsulation of the system call, so when the library function operates on the file, it will inevitably cause the system call. In other words, library function calls are actually made through system calls. For example, the C library function fwrite is implemented through write.
Library function calls can greatly reduce the number of system calls because of buffer technology. Buffers are used for files in both user space and kernel space, and the contents of the kernel buffer are written to the corresponding hardware media only after the kernel buffer is full or finished.
# include # include # include int open (const char * pathname,int flags,int perms); flags:O_RDONLY O_WRONLY O_RDWR O_CREAT if the file does not exist, create a new file and set permissions for it with the third parameter. O_TRUNC if the file already exists, all the original data in the file will be deleted, and the file size will be set to 0 O_APPEND to open the file by adding the returned value: successfully returned file description failed to return-1int fd;fd = open ("test.txt", O_RDWR | O_CREAT | O_TRUNC); if (fd)
< 0){ perror("fail to open");}#include int close(int fd);返回值:成功返回0 失败返回-1#include ssize_t write(int fd,const void *buf,size_t count);功能:像文件描述符fd所指向的文件中写入,从buf开始的缓冲区中count个字节返回值:成功时返回写入的字节数(若为零则表示没有写入数据) 失败时返回-1,并设置errno为相应值。#include ssize_t read(int fd,void *buf,size_t count);功能:从文件描述符fd中读取count字节的数据并放入buf开始的缓冲区中。返回值:成功时返回读取到的字节数 失败时返回-1,并设置errno为相应值。#include #include off_t lseek(int fd, off_t offset, int whence);/***offset:相对与基准点whence的偏移量,以字节为单位,正数表示向前移动,复数表示向后移动*whence:SEEK_SET 文件的起始位置 SEEK_CUR 文件当前读写位置 SEEK_END 文件的结束位置**/返回值:成功时,定位到文件当前读写位置 失败时,返回-1,并设置errno为相应值#define OFFSET 10240int read_len;lseek(fd,-OFFSET,SET_END);while((read_len = read(fd,buf,sizeof(buf))) >0) / / how much to read and write {write (fdd,buf,read_len);}
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 283
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.