OPERATING SYSTEMS

Homework 1 Solution

 

 

 

1.        What is the difference between symmetric and asymmetric multiprocessing?

 

The difference between symmetric and asymmetric multiprocessing: all processors of symmetric multiprocessing are peers; the relationship between processors of asymmetric multiprocessing is a master-slave relationship. More specifically, each CPU in symmetric multiprocessing runs the same copy of the OS, while in asymmetric multiprocessing, they split responsibilities typically, therefore each may have specialized (different) software and roles.

 

2.  What is the difference between a loosely coupled system and a tightly coupled system? Give examples

 

One feature that is commonly characterizing tightly coupled systems is that they share the clock.

Therefore multiprocessors are typically tightly coupled but distributed workstations on a network are not.

Another difference is that: in a tightly-coupled system, the delay experienced when a message is sent from one computer to another is short, and data rate is high; that is, the number of bits per second that can be transferred is large. In a loosely-coupled system, the opposite is true: the intermachine message delay is large and the data rate is low. For example, two CPU chips on the same printed circuit board and connected by wires etched onto the board are likely to be tightly coupled, whereas two computers connected by a 2400 bit/sec modem over the telephone system are certain to be loosely coupled.

 

3.  What is a context switch, what actions are taken in the kernel, and how much time it usually takes in today's systems?

 

Starting and stopping processes is called a context switch. When a context switch occurs, the kernel saves the context of the old process in its PCB and loads the saved context of the new process scheduled to run. Typical speeds range from 1 to 1000 microseconds in today's systems.

 

4.  What are the main types of system calls? Describe their purpose.

 

        end, abort; load, execute; create process, terminate process; get process attributes,                             set process attributes; wait for time; wait event, signal event; allocate and free memory

 

Create file, delete file; open, close; read, write, reposition; get file attributes, set file attributes

 

Request device, release device; read, write, reposition; get device attributes, set device attributes;

Logically attach or detach devices

 

Get time or date, set time or date; get system data, set system data; get process, file, or device attributes; set process, file, or device attributes

 

Create, delete communication connection; send, receive messages; transfer status information;

Attach or detach remote devices

 

5.  Develop a small program in C (or Java) using system calls (e.g. fork(), waitpid(), exit(), kill(), ..)

that does the following:

 

#include <unistd.h>

#include <sys/wait.h>

#include <stdio.h>

#include <signal.h>

 

main()

{

  int child_id,grandson_id,myID;

  child_id = fork();

  if(child_id == 0)  /*child process*/

  {

        myID=getpid();

        printf("the child process ID is: %d\n", myID);

       

        grandson_id =fork();

       

        if(grandson_id ==0) /*grandchild process*/

        {

                printf("grandchild process \n");

                exit();

        }

        sleep(120);

    }

 

    sleep(60);

    kill(0, SIGKILL);        /* Kill all the child process and itself */

}

 

6.  Develop an execution driven simulator (C or Java) for a multiprocessor following these steps:

create a process for every processor (# processors is an argument to the program)

§         in each process start executing a program using the exec() system call (for example a simple program that prints "hello I am processor nr " and the processor number.)

§         each process exits when done

§         the parent process should check when the children are done (i.e., the processors finished execution of their programs) and then exit

 

#include <unistd.h>

#include <sys/wait.h>

#include <stdio.h>

 

main(int argc, char *argv[])

{

        int *cid;

int num_processors=atoi(argv[1]);  /* get # processors from program argument */

cid = (int *) malloc (num_processors * sizeof(int)); /* allocate a dynamic array to store child process ID*/

 

        for( int i=0; i< num_processors; i++)       /* create child process pool */

         {

cid[i]=fork();

if(cid[i]==0)  /*child process*/

                {

                exec(“sampleProgram”);

                exit();

                }

         }

 

/* waiting for all child processes */ 

for(i=0; i< num_processors; i++)    

waitpid(cid[i],0,0);       

 

printf("all child process exited \n ");

free(cid);

}