Final Exam Review: Sample Questions

Study Material, Topics and Sections



  1. Process Concurrency
    Consider a main process p0. You are required to create three more processes using fork() system call. We will identify these processes as p1,p2 and p3. The relationship between the processes are shown below.
    
    a.	Create the processes p1, p2, and p3 as children of P0 (using fork())
    b.	 Redirect “stdout” of p1 to “stdin” of p2 (using dup2())
    c.	Redirect “stdout” pf p2 to “stdin” pf p3
    d.	Let p1 execute (using execl) “ls –l”
    e.	Let p2 execute code to count the number of characters in the input
    f.	Let p3 execute command to get the input and print the output
    

    Answer: pipeEx6.c this folder.
  2. Xinu process and Semaphores Consider the new project revealed by Amazon.com that delivers packages using drones. Lets see if we can help amazon by organizing their fleet of drones. The drones are powered up and ready to go. Each drone has to wait to get (i) the address and (ii) the package. Next they all fly out of a single drone port (droneOut) out of the amazon warehouse. Thus the drone port is can handle only one drone at any time. Once the package is delivered drones come back home through another port (droneIn) that can also handle/allow only one drone at a time. Assume amazon drones are powered by XINU. Use appropriate xinu semaphores to bring order to the amazon drone zone. Clearly show the creation, initialization, usage of the semaphores, in a pseudo code for the operation of the drones. (Hint: you need 4 semaphores some for synchronization and some for mutual exclusion).
    Answer:Decide the number of semaphores, initialize the semaphores (1 for mutex, 0 for synch).
    Decide the critical section/code; wait(..) before critical section/resource, signal(..) after the crtical section/resource.
  3. Signals and Alarms
    a) Write a pseudo code that defines a signal for constant 54 and a handler that counts the number of occurrences of this signal. After it counts it, it resets the signal to allow it re-occur.
    b) Write the main program (pseudo code) that loops forever: inside the loop, it prints the count, it then sleeps for random time and gets interrupted by signal 54 from the keyboard.
    c) How will you interrupt (signal) the main program with a signal 54?
    Answer: signalHandler.c this folder.
  4. Inter-process Communication
    1. Draw the tasks and the pipes between them that are described by the following code segment.
    2. Draw the file descriptor table with the relevant pointers and index numbers.
    3. What is the output from the execution of the code below?
    
    		 int main() {
      pid_t newpid;
      int fd1[2], fd2[2];
    
      char m1[] = "Minecraft Playbook\n";
      char m2[] = "Assemble Silver lining\n";
    
      char rbuf1[256];
      char rbuf2[256];
      int cn1, cn2;
    
      if ((pipe(fd1)== -1)) printf(" error \n");
      printf("fd1 %d %d  \n", fd1[0], fd1[1]);
    
      dup(fd1[0]);
      dup(fd1[1]);               //#1 show the open file descriptor table here
    
      write(4, m1, sizeof(m1));
      cn1 = read(5, rbuf1, 256);
      write(1, rbuf1, cn1);  //#2 show the structure of pipe fd1 with the respect the current process
    
      if ((pipe(fd2)== -1)) printf(" error \n");
      printf("fd2 %d %d  \n", fd2[0], fd2[1]);
    
      if ((newpid = fork()) == -1) { printf("error \n"); return 0;}
    
      if (newpid >0 )
        {   //parent
          write(4, m2, sizeof(m2)); //#3 show the open file descriptor table here
        }
      else { //child
        cn2 = read(3, rbuf2, 256);
        write(1, rbuf2,cn2);
        int fd3[2];
        if ((pipe(fd3)== -1)) printf(" error \n");
        printf("fd3 %d %d  \n", fd3[0], fd3[1]);    //#4 Show the open file descriptor table for parent + child
        // other code
      }
    
      return 0; }
    

    Answer: This requires the figures with pipes, filetables, and outputs.
    we worked on 2 examples. Look at your notes and work it out yourself.
  5. XINU System
    Clearly list the steps in adding a shell command in Xinu. Use code snippets where ever appropriate.
    Answer: You must have done this in xinu lab. Look at the xinu lab handout or xinu wiki for an exampel of echo shell command. DO NOT memorize but learn the concepts.
  6. Device driver
    Define the steps in designing a framebuffer for Xinu. Use code snippets whereever needed.
    Answer: we discussed the design of framebuffer in class. We executed the code for framebuffer.
    Add a frembuf.h in the include folder. This contains the framebuf function prototypes.
    Add a xsh_frmbuf.c in the shell folder to add framebuffer as shell command for testing.
    Add to the number of FRMBUFF in the device.h file of include folder.
    Add an entry the devtable.h file in the systems folder

    See the code here. Upload it to xinu and execute it.


  7. Xinu internals
    (i) What does function call create accomplish in the following command? ready(create((void *)shell, INITSTK, INITPRIO, "SHELL0", 1, CONSOLE),RESCHED_NO);
    (ii) what does function call ready accomplish using the following command? ready(create((void *)shell, INITSTK, INITPRIO, "SHELL0", 1, CONSOLE),RESCHED_YES);
    (iii) In Project 2, how did you use a single WRT54GL –based XINU to chat between two users?
    (iv) What are the three important data structures used in xinu for managing processes, devices and semaphores respectively? Explain their structures.
    Answer:This is directly from the Xinu lab you completed.

  8. Data-driven and control-driven code
    Problem statement, state diagram, table-driven (data-driven) and function-driven(Control-driven) solutions See the xinu lab cyclic executive implementation.
    You are to design part of the embedded control system for an automatic candy vending machine: coin counter. The candy bars inside the machine cost 25 cents, and the machine accepts nickels, dimes, and quarters only. The inputs to the control are a set of three signals that indicate what kind of coin has been deposited, as well as a reset signal. The coin counter should generate an output signal that causes the candy to be delivered whenever the amount of money received is 25 cents or more (no change is given). Once the candy has been delivered, some external circuitry will generate a reset signal to put the control back into its initial state. Identify your inputs and outputs, and draw the finite state machine that represents the logic of this coin counter. (You do not have to write the code; just provide the design in the form of an FSM.)

  9. Answer: You will draw the finite state diagram with states and also the table corresponding to this. This is the type of tbale we used for cyclic executive example. See the code here.
  10. Memory Management
    List 5 important issues when dealing dynamic memory. Explain these issues with an example each.

    Answer: See the link in the class discussion on this topic. Find out where it is? Also see the code here.
  11. Use case modeling
    Analyze a vending machine (embedded RT) system using use-case model.
    Answer: This answer is given in the sidebar of the lecture on use-case analysis. Navigate through the lectures and find out.

How to prepare?

Start with the Lecture tab of course web page. We have covered all these questions during review session on the ast two weeks. Work on the answers to the questions by yourself or in your group study. USe my notes given during the lectures as guidelines.
Also look at the demo code in the demos directory. Locate where it is!
It will help if you work on the concepts based on the course links.