Use LEFT and RIGHT arrow keys to navigate between flashcards;
Use UP and DOWN arrow keys to flip the card;
H to show hint;
A reads text to speech;
69 Cards in this Set
- Front
- Back
What is the system call for opening a file
|
"int open (const char *name, int flags, mode_t mode); "
|
|
What is returned on success of the open system call?
|
The file descriptor
|
|
The three main flag arguments to open are?
|
"O_RDONLY, O_WRONLY, or O_RDWR"
|
|
O_TRUNC is an additional flag that means what?
|
Truncate to a length of zero (start over)
|
|
The mode argument is used for what?
|
Specifying file ownership
|
|
What is O_CREAT?
|
"If the file denoted by name does not exist, the kernel will create it. If the file already exists, this flag has no effect
|
|
The creat function corresponds to what flags in open?
|
O_WRONLY | O_CREAT | O_TRUNC
|
|
What does the creat signature look like?
|
"int creat (const char *name, mode_t mode);"
|
|
The main system call for reading a file is?
|
read
|
|
The signature for read is ?
|
"ssize_t read (int fd, void *buf, size_t len); "
|
|
"On success, read returns what?"
|
The number of bytes successfully read.
|
|
"On error, read returns?"
|
-1
|
|
By default, what will happen if a call is made for len bytes, but no bytes are available for reading
|
The call will block
|
|
Non-blocking reads are possible using...?
|
Open the file with O_NONBLOCK and handle the EAGAIN errror
|
|
What does the signature of write look like?
|
"ssize_t write (int fd, const void *buf, size_t count); "
|
|
What is append mode?
|
"Writes always occur that the end of the file, not where the fd currently points. Even works with two concurrent writers"
|
|
"When a write returns, where is your data? On disk?"
|
"No, a write only takes your buffer and writes it into a kernel buffer. "
|
|
What is "writeback"
|
When the kernel takes all the "dirty" buffers and optimally writes them to disk
|
|
What if prior to writeback a read is issued for that data?
|
The request is then served from memory and not disk!
|
|
Can multiple processes dirty a buffer? Are buffers associated with a process?
|
Yes multiple processes can dirty a buffer. Buffers are not associated with a particular process
|
|
What is the maximum time a buffer can remain in memory before it is written out to disk?
|
"It's configurable, found in .../proc/sys/vm/dirty_expire_centiseconds"
|
|
Why would you want to use synchronized I/O?
|
If you care about when the data hits the disk.
|
|
How does fsync work?
|
Writes all dirty data buffers to disk for a given file
|
|
What is the signature of fsync?
|
int fsync(int fd);
|
|
What is sync
|
"Flushes ALL buffers, not just for one fd"
|
|
"Which runs faster, sync or fsync?"
|
"fsync, sync can take several minutes on a busy machine."
|
|
What is direct I/O?
|
"Bypassing the Kernel's I/O system (caching, buffers, etc...) and doing this all in user space. Some database systems roll their own I/O system."
|
|
How do you do direct I/O?
|
provide the O_DIRECT flag to open()
|
|
What does the O_DIRECT flag do?
|
Bypasses kernel buffers and loads data directly into the user-space buffer provided. All operations are synchronous (won't return until completed)
|
|
What is the signature of the function that closes a file?
|
int close (int fd);
|
|
What does a call to close() do?
|
Unmaps the file descriptor from the file and disassociates the process from the file.
|
|
"When close() is call, will a file be flushed to disk?"
|
No. Closing has no bearing on when this is done.
|
|
Can you move the file position around for a given file descriptor?
|
"Yes, using lseek()"
|
|
What is the signature for lseek()
|
"off_t lseek (int fd, off_t pos, int origin); "
|
|
what are the three values for lseek() origin?
|
"SEEK_CUR, SEEK_END, SEEK_SET "
|
|
How would you set the current file position to be at char 1875?
|
"ret = lseek (fd, (off_t) 1875, SEEK_SET); "
|
|
What is a 'hole'?
|
A padding of zeros (if you write passed the end of the file)
|
|
What is the pread function used for?
|
A variation on the read function that takes a file position as an argument.
|
|
Do pread and pwrite permanently change the file position?
|
"No, upon completion the file position is not updated."
|
|
Why is pread/pwrite preferable to lseek?
|
"Thread safe, it's possible for one app thread to call lseek(), then before it gets a chance to call read/write another app thread calls lseek and changes the position"
|
|
What system call would you use to truncate a file if you have a file descriptor?
|
ftruncate()
|
|
Can you use ftruncate() or truncate() to make a file larger?
|
"Yes, if so, it is padded out with zeros."
|
|
Do the truncate calls update the current file position?
|
No
|
|
"These flags are defined where...O_RDONLY, O_WRONLY, or O_RDWR"
|
fcntl.h
|
|
The functions for using variable arguments to a function is found in...
|
stdarg.h
|
|
The structure that contains the list of variable arguments is of type...?
|
va_list
|
|
"To initialize va_list, you need to call...?"
|
va_start()
|
|
How do you retrieve the value for the next argument?
|
"va_arg(va_list, type)"
|
|
What function ends the program?
|
"exit(1) (1 means error, 0 means success)"
|
|
Blocking on more than one file descriptor at a time (without the use of threads is known as what?
|
Multiplexed I/O
|
|
Why is multiplexed i/o preferable to non-blocking i/o for multiple file descriptors?
|
Non-blocking i/o causes you to read in a loop, continuously tying up resourses. Multiplexed i/o blocks, thus freeing up the processor.
|
|
What does select's signature look like?
|
int select (int n,
fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout); |
|
What are the three interfaces for multiplexed i/o?
|
Select, poll and epoll
|
|
What is the timeout argument used for in select?
|
If the timeout arg is not null, the call will return after that time period if no fd's are ready for I/O
|
|
The first arg to select (n), what is that?
|
n is equal to the value of the highest valued file descriptor in any set, plus one
|
|
T or F, the timeval must be reinitialized after every call?
|
True, it must be reinitialized
|
|
The file descriptor sets used by select are implemented using what data structure?
|
bit arrays
|
|
How many bytes would you need to represent a range of 0 to 1024 file descriptors (1024 is the default)?
|
128 bytes
|
|
An file descriptor set (used by select) is of type...?
|
fd_set
|
|
How can I clear all fd's from an fd_set called myset?
|
FD_ZERO(&fd_set);
|
|
How can we add a file descriptor to a given set?
|
FD_SET(fd, &fd_set);
|
|
How can we remove a file descriptor from a given set?
|
FD_CLR(fd, &fd_set);
|
|
How can we check if a file descriptor is set?
|
FD_ISSET(fd, &fd_set));
|
|
On success, select returns what?
|
The number of fd's ready for I/O
|
|
Why use select as a portable subsecond-resolution sleep?
|
Implemented on lots of Unix systems, call would be select(0,NULL, NULL, NULL, &time);
|
|
What's the diff between select() and pselect()?
|
pselect does not reset the timeout param, so no need to reinitialize each time. And pselect uses the sigmask parameter.
|
|
What the signature of poll look like?
|
int poll (struct pollfd *fds, unsigned int nfds, int timeout);
|
|
Instead of using 3 fd_set structures like select(), epoll uses an array of what?
|
struct pollfd
|
|
What does a struct pollfd look like?
|
struct pollfd {
int fd; /* file descriptor */ short events; /* requested events to watch */ short revents; /* returned events witnessed */ }; |