HW 6: System Calls and Device I/O
Instructions
You must turn in a sheet of paper that is neatly typed or written answering the questions below. (You are strongly encouraged to type your homework.)
You can use the following tex file to get started with preparing your homework.
- This homework is graded out of 100 points. Point values are associated to each question.
Questions
- (5 points) Why does the operating system perform system calls as oppose to having each user perform the same operations themselves?
- (10 points) Look up the following C functions in the man page, label them as
either a system call or not a system call.
- fread()
- write()
- stat()
- mmap()
- execv()
- (10 points) Run
ic221-up
. In thehw/06/prob3
directory you'll find a compiled program. Useltrace
to enumerate the library function calls occurring undermain()
. - (10 points) Run
ic221-up
. In thehw/06/prob4
directory you'll find a compiled program. Usestrace
to enumerate the system function calls occurring undermain()
. (20 points) Consider a file,
accts.dat
, which stores 1000 accounts formatted based on the defined structure. Usingopen()
andread()
, complete the program below to print them out:#include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <fcntl.h> typedef struct{ long acctnum; double bal; char acctname[1024]; } acct_t; void read_accts(accts){ //COMPLETE ME } int main(int argc, char *argv[]){ acct_t accts[1000]; read_accts(accts); int i; for(i=0;i<1000;i++){ printf("%ld (%f) -- %s\n", accts[i].acctnum, accts[i].bal, accts[i].acctname); } close(fd); }
- (10 points) Complete the following ORing options that matching the
fopen()
permissions:r
w
a
w+
r+
- (10 points) Consider a
umask
of 0750 (the leading 0 is to indicate a number written in octal). For the followingopen()
permissions, what actual permission will the file get? You can write your answers in octal.- 0777
- 0640
- 0740
- 0501
- 0651
- (5 points) Explain why the umask is considered a security feature.