CS代考 Problem 2. This problem is to help vou understand the semantics of reading

Problem 2. This problem is to help vou understand the semantics of reading and writing. You
are encouraged to write some code and experiment with it to help get the answers. (Reading the
textbook is also a good idea!)
a. Suppose the file “foo” contains the 10 characters cs270rocks. A program does the following:

Copyright By PowCoder代写 加微信 powcoder

int main() f
char buf[10];
int Id = open (“foo”, 0 RDWR);
int n = read (fd, buf, 10) ;
It then calls printf (“read %d bytes: %\n” ,n, buf). What will happen?
b. Suppose instead that after the second line above, the program does:
read(fd, bur ,5) ;
/ XXX should check return value!
write (fd, “is hard”, 7); // xxx ditto
read (fd, buf , 5) ;
close (1d) ;
What would the file contain after the program calls close? Be specific
c. What value would the second call to read) above return?
d. What can you say about how the operating system keeps track of which bytes should be read
from a file, and where in the file the bytes in a write should be placed?
Problem 3. One of an operating system’s main jobs is to keep track of resource usage, and enforce
limits on things like CPU cycles used by a process, amount of disk space taken up by a user’s home
directory, etc. The command “prlimit” prints various system limits on things like file sizes.
A. Run the command prlimit on your VM. What is limit on file size? How about CPU time?
b. The stat) system call returns information about the file associated with a given pathname.
It. takes a pointer to a struct stat, and fills in that structure with the file’s inode (vode)
number, permissions, owner, and size in bytes. Obviously this information has to be encoded
in some C language type field. Refer to the man page for stat to see what type the size of the
file is returned in. How bit (how many bits) is this integer type? What is the largest number
that can be represented in that type? (Hint: write a little program that uses the sizeof
operator to find the size of off_t.)
What does this tell you about the information printed by primit?

程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com