Assignment 4 1. a. Differentiate between multiprogramming & multiprocessing Answer Multiprogramming is the process of loading more than one program into the memory so that processor can be kept busy by switching between any of the loaded programs. Multiprogramming is a rudimentary form of parallel processing in which several programs are run at the same time on a uniprocessor. Since there is only one processor, there can be no true simultaneous execution of different programs. Instead, the operating system executes part of one program, then part of another, and so on. To the user it appears that all programs are executing at the same time. But multiprocessing mainly deals with the hardware. Here more than one processing unit (CPU) comes into the picture. Multiprocessing leads to parallel computing. Multiprocessing is the coordinated processing of programs by more than one computer processor. Multiprocessing is a general term that can mean the dynamic assignment of a program to one of two or more computers working in tandem or can involve multiple computers working on the same program at the same time (in parallel). b. Explain the process control and file management using system calls Process control Answer Process control 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 File management create file, delete file open, close read, write, reposition oget file attributes, set file attributes c .What are the different ways in which the Pthread terminates There are several ways in which a thread may be terminated: 1. The thread returns normally from its starting routine. Its work is done. 2. The thread makes a call to the pthread_exit subroutine - whether its work is done or not. 3. The thread is canceled by another thread via the pthread_cancel routine. 4. The entire process is terminated due to making a call to either the exec() or exit() 5. If main() finishes first, without calling pthread_exit explicitly itself 6. The pthread_exit() routine allows the programmer to specify an optional termination status parameter. This optional parameter is typically returned to threads "joining" the terminated thread (covered later). 7. In subroutines that execute to completion normally, you can often dispense with calling pthread_exit() - unless, of course, you want to pass the optional status code back. 8. Cleanup: the pthread_exit() routine does not close files; any files opened inside the thread will remain open after the thread is terminated. 9. pthread_exit (status) 10. pthread_cancel (thread) 11. pthread_attr_destroy (attr) 2. Consider the following set of processes, with the length of the CPU-burst time given 9M in milliseconds: Process Burst Time Priority P1 10 3 P2 1 1 P3 2 3 P4 1 4 P5 5 2 The processes are assumed to have arrived in the order P1, P2, P3, P4, P5, all at time 0. a. Draw four Gantt charts illustrating the execution of these processes using FCFS, SJF, a non-preemptive priority (a smaller priority number implies a higher priority), and RR (quantum = 1) scheduling. b. What is the turnaround time of each process for each of the scheduling algorithms in part a? c. What is the waiting time of each process for each of the scheduling algorithms in part a? d. Which of the schedules in part a results in the minimal average waiting time (over all processes)? 3. Differentiate between user level thread and kernel level thread Kernel Level Thread User Level Thread OS managed threads are called kernel- . User-Level threads are managed entirely level threads or light weight processes. by the run-time system (user-level library). No runtime system is needed in this case run-time system needed Light Weight Heavy Weight The kernel-level threads are slow and User-Level threads are hundred times faster inefficient. than Kernel-Level threads. Because kernel has full knowledge of all Simple Representation: Each thread is threads, Scheduler may decide to give represented simply by a PC, registers, stack more time to a process having large and a small control block, all stored in the number of threads than process having user process address space. small number of threads Kernel-level threads are especially good Simple Management: This simply means for applications that frequently block. that creating a thread, switching between threads and synchronization between threads can all be done without intervention of the kernel. Since kernel must manage and schedule Fast and Efficient: Thread switching is not threads as well as processes. It require a much more expensive than a procedure full thread control block (TCB) for each call. thread to maintain information about threads. As a result there is significant overhead and increased in kernel complexity. b. Process and thread Both processes and threads are independent sequences of execution. The typical difference is that threads (of the same process) run in a shared memory space, while processes run in separate memory spaces. Threads Will by default share memory Will share file descriptors Will share file system context Will share signal handling Processes Will by default not share memory Most file descriptors not shared Don't share file system context Don't share signal handling C. Explain the different states of a process As a process executes, it changes state 4 new: The process is being created running: Instructions are being executed waiting: The process is waiting for some event to occur ready: The process is waiting to be assigned to a processor terminated: The process has finished execution a. Consider a system consisting of m resources of the same type, being shared by n processes. Resources can be requested and released by processes only one at a time. Show that the system is deadlock free if the following two conditions hold: i. The maximum need of each process is between 1 and m resources ii. The sum of all maximum needs is less than m + n. b. Consider the following snapshot of a system: 4M 5M Answer the following questions using the banker’s algorithm: c. What is the content of the matrix Need? d. Is the system in a safe state? e. If a request from process P1 arrives for (0,4,2,0), can the request be granted immediately Answer 5 a. Define operating system? List the different services provided by the OS.4M Answer OS is a resource allocator Manages all resources Decides between conflicting requests for efficient and fair use OS is a control Program Controls execution of programs to prevent errors and improper use computer Services Provided by OS are as follows 1. User interface 2. Program execution 3. I/O operations 4. File-system manipulation 5. Communications 6. Error detection 7. Resource allocation 8. Accounting 9. Protection and security