Using read() and write() system calls to access mm

2019-09-17 01:03发布

问题:

I wish to ask whether is it possible to implement an mread() function using only system calls such as read() and write(). I know that the standard C library functions such as fread() and fwrite() use a type of buffer to read. I want to do the same but this time I want to read() and write() from a buffer to a memory mapped region and vice versa. For example my mread() wants to read from memory map and store into buffer. Does it make sense to create a new fd just to use it as my TEMPORARY buffer. Then I use read() to read from memory mapped region into the fd..and then use write() to store the contents in fd into my actual buff.
I hope I was clear :) ..Thank you for your help!

回答1:

I hope I was clear

Unfortunately, not very. But it sounds like you want to use the pipe system call. It opens two fds. Whatever's written on the write end can be read on the read end. If you're doing all of this in a single thread you have to be careful though, because you might run out of buffer space and the read/write call will then hang indefinitely.



标签: c linux mmap