CS703 - Advanced Operating Systems
Course Page
Q & A
Short Question & Answers
Q1: What are the five major activities of an operating system in regard to process management?
Five major process management activities of an operating system are
a. creation and deletion of user and system processes.
b. suspension and resumption of processes.
c. provision of mechanisms for process synchronization.
d. provision of mechanisms for process communication.
e. provision of mechanisms for deadlock handling.
Q2: What are the three major activities of an operating system in regard to memory management?
Three major memory management activities of an operating system are
a. keeping track of which parts of memory are currently being used, and by whom.
b. deciding which processes are to be loaded into memory when memory space becomes available.
c. allocating and freeing memory space as needed.
Q3: What are the three major activities of an operating system in regard to secondary-storage management?
Three major secondary-storage management activities of an operating system are free-space management, storage allocation, disk scheduling.
Q4: What are the five major activities of an operating system in regard to file management?
Five major file management activities of an operating system are
a. creation and deletion of files.
b. creation and deletion of directories.
c. support of primitives for manipulation files and directories.
d. mapping of files and directories onto secondary storage.
e. backup of files on stable (nonvolatile) storage media.
Q5: What is the purpose of the command interpreter? Why is it usually separate from the kernel?
The command interpreter is the interface between the user and the operating system. Its function is simple: to get the next command statement and execute it.

Because that some operating systems include the command interpreter in the kernel.
Q6: List five services provided by an operating system. Explain how each provides convenience to the users. Explain in which cases it would be impossible for user-level programs to provide these services.
Five services that are provided by an operating system are
a. program execution. The OS provides for the loading of programs into memory and managing the execution of programs. The allocation of CPU time and memory could not be properly managed by the users' programs.

b. I/O operation. User-level programs should not be allowed to perform I/O operations directly for reasons of efficiency and security. Further, a simple I/O request by a user-level program typically entails a long sequence of machine language and device-control commands.

c. file-system manipulation. This service takes care of the housekeeping and management chores associated with creating, deleting, naming, and protecting files. User programs should not be allowed to perform these tasks for security reasons.

d. communications. The OS takes care of the complex subtasks involved in exchanging information between computer systems. It is neither desirable (because of the number and complexity of the lower-level subtasks involved) nor advisable (for security reasons) to let user-level programs handle communications directly.

e. error detection. This service includes the detection of certain errors caused by hardware failure (faults in memory or I/O devices) or by defective/malicious software. A prime directive for a computer system is the correct execution of programs, hence the responsibility of this service cannot be shifted to user-level programs.
Q7: What is the purpose of the system calls?
System calls provide the interface between processes and the operating system. These calls are usually available both from assembly-language programs and from higher-level language programs.
Q8: What are the main types of system calls? Describe their purpose.
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; get file attributes, set file attributes

Device management:
Request device, release device; read, write, reposition; get device attributes, set device attributes; Logically attach or detach devices

Information maintenance:
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
Q9: A total of how many processes would be created in the function fork test () given below, excluding the main process that called fork test()? How many times will “Whatsup” be printed. Briefly explain your answer.
void fork_test( ) {
            if (fork() != 0) {
                 if (fork() != 0)
                       printf(“Hello 1 \n”);
           } else {
                if (fork() != 0) {
                       printf(“Hello \n”);
                } else {
printf("Whatsup \n");
Five process create in this process excluding the fork test (). Whatsup line prints six times in this coding because each process print this line. fork test () method contain (fork()!=0) condition that is false in case of child process because child process fork() return 0 value. This condition is true for parent process because it return non zero value. If it return -1 then it contain error. First we consider parent process. It enter to this method and then check again condition that is false for child process and true for parent process. Parent process again call fork() method and make child process. Second (fork()!=0) condition that is false for child process run else portion of if condition and print hello line. Now we consider child process of 1st condition (fork()!=0) that is false for child process so we come to the else portion. In the else portion there is another (fork()!=0) condition. That is true for parent so parent process print hello line and this condition false for child process so it come to else portion and call fork() method and make child process. At the end each process print Whatsup line. As we know that is 6 process so it print 6 times Whatsup line
Q10: Describe what problems would happen when multiple threads will execute the following C statement; also justify your answer with proper reasons.
{ static int I; I++; }
1. Incorrect ordering: When two thread increment the counter but the result is 1 instead 2.

2. Concurrence issues: when executing static methods concurrently are static fields, which only exist one time. So, if the method reads and writes static fields, concurrence issues can occur In concurrent environment two or many threads can run concurrently, if all threads are trying to update some shared resource concurrently, there might be chance that threads trying to read shared resource get stale data and produce wrong outputs.

3. Deadlock problem: A deadlock occurs when each of two threads tries to lock a resource the other has already locked. Neither thread can make any further progress. Deadlock occur when two of many thread are waiting for two or more resources, where each thread need to get access on all resources to progress and those resources are acquired by different threads and waiting for other resources to be release, which will not be possible ever. For example, two threads A and B need both resources X and Y to perform their tasks. If thread A acquires resource X and thread B acquires Y and now both threads are waiting for resources to be release by other thread. Which is not possible and this is called deadlock. You need to take care of the way of your synchronization if this is going to be a cause of deadlock.

4. Race condition problem: A race condition is a bug that occurs when the outcome of a program depends on which of two or more threads reaches a particular block of code first. Running the program many times produces different results, and the result of any given run cannot be predicted. In a multithreaded application, a thread that has loaded and incremented the value might be preempted by another thread which performs all three steps; when the first thread resumes execution and stores its value, it overwrites objCt without taking into account the fact that the value has changed in the interim. When writing multi-threaded applications, one of the most common problems experienced are race conditions. A race condition occurs when two or more threads can access shared data and they try to change it at the same time. Because the thread scheduling algorithm can swap between threads at any time, you don't know the order in which the threads will attempt to access the shared data. Therefore, the result of the change in data is dependent on the thread scheduling algorithm, i.e. both threads are "racing" to access/change the data A "race condition" exists when multithreaded (or otherwise parallel) code that would access a shared resource could do so in such as way as to cause unexpected results.

5. Visibility problem: Visibility of shared object could be different for different threads. This is one of the problems of multi-threading environment. Suppose there are two threads, one is writing any shared variable and other is reading from shared variable. When reading and writing will be occur in different threads, there is no guarantee that reader thread will see the value written by writer thread. This problem of multi-threading is known as visibility issue of shared resource. This problem can be resolved with proper synchronization of shared resource.
Course Instructor

Mr. Farhan Zaidi
MS Computer Science
University of Southern California, USA

Modern Operating Systems by Tanenbaum

Operating Systems Internals and Design Principles by William Stallings

Operating Systems by Gary Nutt

Computer Systems: A programmer’s perspective
by Randal E. Bryant & David R.