[cs33211] reading/writing to random positions in the file
Mikhail Nesterenko
mikhail at cs.kent.edu
Fri Apr 24 17:36:25 EDT 2009
File descriptor is a unique identifier that the OS provides for each
file that the program opens (we covered it in class). Since we are
using low-level read/write operations, using C++ streams would be
awkward. Instead, I recommend using open() and close() functions. Open
returns the file descriptor of the opened file. See
man -S 3p open
for more details.
Thanks,
--
Mikhail
> Hi,
>
> I don't think I understand what the FIle Descriptor is?
>
> On Thu, Apr 23, 2009 at 3:46 PM, Mikhail Nesterenko <mikhail at cs.kent.edu> wrote:
> > OS students,
> >
> > There are two ways to do it:
> >
> > * either use "pread" (for position read) and "pwrite" (for position
> > write) the functions take three arguments:
> > 1. file descriptor
> > 2. pointer to the buffer holding values to be written to file/read
> > form file
> > 3. offset -- specifies the location where the write/read should
> > start
> >
> > pread/pwrite are described in the same man-page as the read/write
> >
> > * function lseek positions the open file default offset to the
> > particular value. In this case you can use regular read/write but
> > you have to lseek before each read/write operation.
More information about the cs33211
mailing list