Operating System Homework #1

  1. [1.8]What is the purpose of interrupts? What are the differences between a trap and an interrupt? Can traps be generated intentionally by a user program? If so, for what purpose?
  1. [1.10]Some computer systems do not provide a privileged mode of operation in hardware. Is it possible to construct a secure operating system for these computer systems? Give arguments both that it is and that it is not possible.
  1. [1.13] Discuss, with examples, how the problem of maintaining coherence of cached data manifests itself in the following processing environments:

(a)Single-processor systems

(b)Multiprocessor systems

(c)Distributed systems

  1. [2.4] What are the five major activities of an operating system in regard to file management?
  1. [2.6] Would it be possible for the user to develop a new command interpreter using the system-call interface provided by the operating system?
  1. [2.10] What is the main advantage of the microkernel approach to system design? How do user programs and system services interact in a microkernel architecture? What are the disadvantages of using the microkernel approach?
  1. [2.11] What are the advantages of using loadable kernel modules?
  1. [3.1] Describe the differences among short-term, medium-term, and long-term scheduling.
  1. [3.2] Describe the actions taken by a kernel to context-switch between processes.
  1. [3.5] Including the initial parent process, how many processes are created by the following program?

#include <stdio.h>
int main()
{
int i;
for (i = 0; i < 4; i++) {
fork();
printf("%d\n",getpid());
}
return 0;
}
  1. [3.10] Using the following program, explain what the output will be at lines X and Y.

#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#define SIZE 5
int nums[SIZE] = {0,1,2,3,4};
int main()
{
int i;
pid_t pid;
pid = fork();
if (pid == 0) {
for (i = 0; i < SIZE; i++) {
nums[i] *= -i;
printf("CHILD %d\n",nums[i]); /* LINE X */
}
}
else if (pid > 0) {
wait(NULL);
for (i = 0; i < SIZE; i++)
printf("PARENT: %d\n",nums[i]); /* LINE Y */
}
return 0;
}
  1. [3.14] The Collatz conjecture concerns what happens when we take any positive integer n and apply the following algorithm:

n =

The conjectures states that when this algorithm is continually applied, all positive integers will eventually reach 1. For example, if n = 35, the sequence is

35, 106, 53, 160, 80, 40, 20, 10, 5, 16, 8, 4, 2, 1

Write a C program using the fork( ) system call that generates this sequence in the child process. The starting number will be provided from the command line. For example, if 8 is passed as a parameter on the command line, the child process will output 8, 4, 2, 1. Because the parent and child processes have their own copies of the data, it will be necessary for the child to output the sequence. Have the parent invoke the wait( ) call for the child process to complete before exiting the program. Perform necessary error checking to ensure that a positive integer is passed on the command line.

1