Ex1

来源:互联网 发布:登陆阿里云服务器 编辑:程序博客网 时间:2024/05/19 22:43

Please show all work on a separate sheet attached to this sheet.
    (50 points)

    1. What are the two main functions of an operating system?
       What is multiprogramming?
       (5 points)
   
Ans: 1) An operating system must provide the users with an extended
         (i.e., virtual) machine, and it must manage the I/O devices and
         other system resources.
      2) Multiprogramming is the rapid switching of the CPU between multiple
         processes in memory. It is commonly used to keep the CPU busy while one
         or more processes are doing I/O.


    2. Refer to the section 1.3 and pick up one type of operating
       systems of your interest. List at least two examples of your
       pick and list their main features.
       (10 points)

  Ans: Operating systems for palmtop computers and embedded systems are picked.
      
       1) Palm OS
          Developed by PalmSource, Inc.
          Features:
          o Built-in Personal Information Manager (PIM) programs       
          o Work with a PC
          o One-tap ease of use
          o Wired and wireless communication

       2) Pocket PC
          Developed by Microsoft Corporation
          Features:
          o Built-in Personal Information Manager (PIM) programs
          o Can run popular Microsoft applications
          o Wired and wireless communication
        
    3. A typical use of the fork system call is to allow a server to
       create a slave to service an incoming request. However, if
       the time required to process the request is very short, it is
       common to have the server process the request without taking
       the time to fork off a child process. For example, suppose that
       it takes x msec to create a process using fork and y msec to
       service the request. (10 points)

       (a) If x is much smaller than y, should a slave be created to
           service the request? Explain.

       (b) If y is much smaller than x, should a slave be created to
           service the request? Explain.

  Ans: (a) If x is much smaller than y, a slave should be created to
           service the request because the time required to process
           the request is long  and the overhead of forking a new
           process would be negligible.

       (b) If y is much smaller than x, a slave should not be created
           to service the request because the time required to process
           the request is very short and the overhead of forking a
           new process would be substantial.

    4. For each of the following system calls, give a condition that
       causes it to fail: fork, exec, and unlink.
       (5 points)

  Ans: Fork can fail if there are no free slots left in the process table (and
       possibly if there is no memory or swap space left).
       Exec can fail if the file name given does not exist or is not a valid
       executable file.
       Unlink can fail if the file to be unlinked does not exist or the calling
       process does not have the authority to unlink it.


    5. In Fig 2-10, a multithreaded Web sever is shown. If the only
       way to read from a file is the normal blocking read system
       call, do you think user-level thread or kernel-level threads
       are being used for the Web server? Why?
       (10 points)

  Ans: A worker thread will block when it has to read a Web page from the
       disk. If user-level threads are being used, this action will block
       the entire process, destroying the value of multithreading. Thus
       it is better that kernel threads are used to permit some threads
       to block without affecting the others.


    6. Consider the following section of code:

        main()
        {
            int pid;
            pid = fork();
            if (pid > 0) {
                printf("In child./n");
                exit(0);
            }
            printf("In parent./n");
        }

        Assume that the fork() system call is successful. What will be
        printed when the code is executed? If there is an error, how can
        it be fixed?

        What happens if the fork() system call is not successful.
        (10 points)

  Ans: 1) The following will be printed:

       In child.
       In parent.

       The code can be fixed as follows:

        main()
        {
            int pid;
            pid = fork();
            if (pid = 0) {
                printf("In child./n");
                exit(0);
            }
            printf("In parent./n");
        }

       2) If the fork() system call is not successful, the return value of the
          fork() system call is -1.  The fixed code will only show
         
          In parent.

原创粉丝点击