IC221: Systems Programming (SP18)

Home Policy Calendar Units Assignments Resources

HW 6: System Calls and Device I/O


  • 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.


  1. (5 points) Why does the operating system perform system calls as oppose to having each user perform the same operations themselves?
  2. (10 points) Look up the following C functions in the man page, label them as either a system call or not a system call.
    1. fread()
    2. write()
    3. stat()
    4. mmap()
    5. execv()
  3. (10 points) Run ic221-up. In the hw/06/prob3 directory you'll find a compiled program. Use ltrace to enumerate the library function calls occurring under main().
  4. (10 points) Run ic221-up. In the hw/06/prob4 directory you'll find a compiled program. Use strace to enumerate the system function calls occurring under main().
  5. (20 points) Consider a file, accts.dat, which stores 1000 accounts formatted based on the defined structure. Using open() and read(), 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){
    int main(int argc, char *argv[]){
      acct_t accts[1000];
      int i;
        printf("%ld (%f) -- %s\n",
  6. (10 points) Complete the following ORing options that matching the fopen() permissions:
    1. r
    2. w
    3. a
    4. w+
    5. r+
  7. (10 points) Consider a umask of 0750 (the leading 0 is to indicate a number written in octal). For the following open() permissions, what actual permission will the file get? You can write your answers in octal.
    1. 0777
    2. 0640
    3. 0740
    4. 0501
    5. 0651
  8. (5 points) Explain why the umask is considered a security feature.