In: Computer Science
1) What is preemption? What is its purpose?
2) What is swapping? What is its purpose?
3) Name 5 major activities of an OS with respect to process management. Why is each required?
4) Why is a mode switch between threads cheaper than a mode switch between processes?
1) Pre-emption refers to the temporary interruption and suspension of a task, without asking for its cooperation, with the intention to resume that task later. This act is called a context switch and is typically performed by the pre-emptive scheduler, a component in the operating system authorized to pre-empt, or interrupt, and later resume tasks running in the system.
Some systems have preemptive kernels that permit tasks to be preempted even in kernel mode. Examples of such systems are Solaris 2, Windows NT, Linux, Advanced Interactive eXecutive and Berkeley Software Distribution.
2)
Swapping was an older form of memory management. It was moving from/to secondary storage a whole program at a time, in a scheme known as roll-in/roll-out. Now swapping is a fairly close synonym of paging.
Memory management is a way in which computer can store and retrieve data from secondary storage for use in main memory.
So, we can say that the purpose of swapping, or paging, is to access data being stored in hard disk and to bring it into the RAM so that it can be used by the application program. Remember that swapping is only necessary when that data is not already in the RAM.
3)
Process Creation
When you first turn on your computer, the operating system opens processes to run services for everything from the print spooler to computer security. When you log in to the computer and start programs, the programs create dependent processes. A process is not the program itself, but rather the instructions that the CPU uses to execute the program. A process either belongs to Windows or to some other program that you have installed.
Processing State
The state of a process may be "created," "running," "waiting," or "blocked." You can say that a process is "waiting" the moment after you start its parent program, and before it has been processed by the CPU. A process is "running" when the CPU is processing it. You can consider a process "blocked" if the computer does not have enough memory to process it or if files associated with the process cannot be located. All operating systems have some sort of process handling system, though they have different names for each state.
Process Synchronization
Once processes are running, the operating system needs a way to ensure that no two processes access the same resources at the same time. Specifically, no two processes can attempt to execute the same area of code at once. If two processes did attempt to execute this code at the same time, a crash could occur as they attempt to call the same files and send the same instructions to the CPU at the same time. If two processes need to run the same code, one must wait for the other to finish before proceeding.
Process Communication
The computer must ensure that processes can communicate with the CPU and with each other. For example, a program can have many processes, and each process can have a different permission level. A permission level is simply an indication of the level of access a process should have to the system. Process communication ensures that the computer can determine the permissions of each process. This is very important in preventing malware from deleting system files or adding instructions to the operating system itself.
Deadlock Prevention
Finally, the computer must have a way to ensure that processes do not become deadlocked. Deadlock occurs when two processes each require a resource that the other is currently using, and so neither process can finish what it is doing. The resources cannot be released, and programs lock up. You can also refer to this situation as a "circular wait." Operating systems prevent deadlock in different ways, but the most common method is to force a process to declare the resources it will need before it can start up. Alternatively, a process may be forced to request resources in blocks, and then release the resources as it finishes with them.
4) 1. reason – the control blocks for processes are larger
than for threads (hold more state information), so the
amount of information to move during the thread switching
is less than for process context switching
2. reason – the major reason is that the memory management
is much simpler for threads than for processes. Threads
share their memory so during mode switching, memory
information does not have to be exchanged/changed, pages
and page tables do not have to be switched, etc. This makes
the thread context switch much cheaper than for processes.
In case of processes the memory pieces (pages) need to be
exchanged, etc. (Will talk about the details in few weeks).
3. reason – threads do not have to worry about accounting,
etc, so do not have to fill out all the information about
accounting and other process specific information in their
thread control block, so keeping the thread control block
consistent is much faster
4. reason – threads share files, so when mode switch
happens in threads, these information stay the same and
threads do not have to worry about it (similar to
accounting information) and that makes the mode switch much
faster.