cat command to achieve

1, read write is the most basic and common io operation is the application layer and kernel layer of communication media, how to read, write achieve cat function?

Clear that we are reading the file and then displayed is the output file out Description 2

Is simple to implement main idea is to familiarize yourself with the process

Pseudocode ideas:

#include <stdio.h>

int main(int argc,int argv[])

{

int fd = open (argv [1], O_RDONLY); first file handle to know where to determine a good read

char buf[250];

int ret = read(fd,buf,sizeof(buf));

write(1,buf,ret);

close(fd);

return 0;

}

Published 165 original articles · won praise 26 · views 30000 +

Guess you like

Origin blog.csdn.net/weixin_42269817/article/details/104842340