What is the difference between read and pread in unix?

前端 未结 4 2086
孤城傲影
孤城傲影 2020-12-13 06:59

What is the difference between the functions read() and pread() in unix?
When choosing between them, what points should I take into considerati

4条回答
  •  爱一瞬间的悲伤
    2020-12-13 07:25

    Pread() works just like read() but reads from the specified position in the file without modifying the file pointer.

    You would use it when you need to repeatedly read data at fixed offset, for example a database index that points to individual records in file, to save on seek() calls.

    Basically use read() if your data is sequential or pread() if you know, or can calculate offset at which to read.

提交回复
热议问题