Friday, December 1, 2006

Semaphore

Defination of Semaphore:
A mechanism for restricting access to critical sections of code
to a single user or process at a time.

Defination of Critical section :
A segment of code in which a thread uses resources (such as certain instance variables) that can be used by other threads, but that must not be used by them at the same time.

The Major activities of Operating system :
1.What are the five major activities of an OS in regard to process management?
Creation and deletion of both user and system processes
Suspension and resumption of processes
Mechanisms for processes
Mechanisms for process synchronization
Mechanisms for process communication
Mechanisms for deadlock handling

2.What are three major activities of an operating system in regard to memory
management?
Keep track of which parts of memory are currently being used & by whom
Decided which processes are to be loaded into memory
Allocated and de-allocate memory space as needed.

3. What are the three major activities of an operating system in regard to Secondary storage management
Free-space management
Storage allocation
Disk scheduling

4. What are the five major activities of an operating system in regard to file management?
Creation and deletion of files
Creation and deletion of directories
Supporting manipulating files and directories
Mapping of files onto secondary storage
Backup of files on stable storage media

5. List five services provided by an operating system.
Program execution
I/O operations
File-system manipulation
Communications
Error detection

6. List three methods for passing parameters needed by system calls.
Pass parameters in registers
Registers pass starting addresses of blocks of parameters
Parameters can be placed, or pushed, onto the stack by the program, and
popped off the stack by the operating system

7. Describe the differences among short-term, medium-term and long-term scheduling.
Short-term (CPU schedular) –
Selects from jobs in memory, those jobs which are ready to execute and allocates the CPU to them

Medium-term
Used especially with time-sharing systems as an intermediate scheduling level. A swapping scheme is implemented to remove partially run programs from memory and reinstate them later to continue where they left off

Long-term (job schedular)
Determines which jobs are brought into memory for processing.

8. What two advantages do threads have over multiple processes? What major disadvantages do they have?
Threads are very inexpensive to create and destroy, and they use very little resources while they exist. They do use CPU time but they don't have totally separate memory spaces.

Threads must trust each other not to damage shared data
Any program that may do more than one task at once could benefit from multitasking. For instance, a program that reads input, processes it and outputs it could have three threads, one for each task.
"Single-minded" process would not benefit from multiple threads; for instance, a program that displays the time of day.

9. What resources are used when a thread is created? How do they differ from those used when a process is created?
A context must be created, including a register set storage location for storage during context switching, and a local stack to record the procedure call arguments, return values, and return address, and thread-local storage. A process creation results in memory being allocated for program instructions and data, as well as thread-like storage. Code may also be loaded into the allocated memory

10. What are the differences between user-level threads and kernel-supported threads? Under what circumstances is one type"better" than the other?
User-level threads have no-kernel support, so they are very inexpensive to create, destroy and switch among. However, if one blocks, the whole process blocks. Kernel-supported threads are more expensive because system calls are needed to create and destroy them and the kernel must schedule them. They are more powerful because they are independently scheduled and block individually.

11. Describe five implementations of the create-new process mechanism.
a. parent continues executing
b. parent stops executing until children are done
c. parent and children share all variables
d. children share only a subset of parent's variables
e. parent and children share no common resources

12. Define the difference between preemptive and nonpreemptive scheduling?
State why strict nonpreemptive scheduling is unlikely to be used in a
computer centre.
Preemptive scheduling allows a process to be interrupted in the midst of its execution, taking the CPU away and allocating it to another process.

Nonpreemptive scheduling ensures that a process relinquishes control of the CPU only when it finishes with its current CPU burst.

13. What is indefinite blocking? How can it occur?
Also call starvation. A process with low priority that never gets a chance to execute. Can occur if CPU is continually busy with higher priority jobs.

14. What are the advantages and disadvantages of deterministic modelling?
Advantage: simple to compute
Disadvantage: results apply only to the specified job set.

15. What are the advantaes and disadvanteages of using implementation to compare various scheduling algorithm?
Advantage: completely accurate
Disadvantage: cost in coding, modifying operating system, modifying data structures

16. What is the meaning of the term busy waiting? What other kinds of waiting are there? Can busy waiting be avoid together?
A process is waiting an event to occur and it does so by executing instructions
A process is waiting for an event to occur in some waiting queue
(e.g. I/O, semaphore) and it does so without having the CPU assigned to it.

17. What is a critical section?
A section of code that only one process at a time can be executing.

18. What is the critical-section problem?
To design an algorithm that allows at most one process into the critical section at a time, without deadlock.

19. What three requirements must a solution to the critical section problem satisfy?
Mutual exclusion, progress, bounded waiting

20. What does execute " atomically" mean?
Execute as a group, with no context switches possible until all of the statements in the group are completed.

21. Define the wait-(postpone) operation, wait(S).
While semaphore is nonpositive, wait; when semaphore becomes positive, subtract one and exit.

22. Define the wakeup operation, signal(S).
Add 1 to the semaphore

23. Is it possible to have a deadlock involving only one single process?
No. this follows directly from the hold-and-wait condition.

24. List types of resources we might consider in deadlock problems on computers.
CPU cycles, memory spaces, files, I/O devices, tape drive, printers

25. What are the four necessary conditions needed before deadlock can occur?
a. at least one resource must be held in a nonsharable mode
b. a process holding at least one resources is waiting for more resources held by other processes
c. resources cannot be preempted
d. there must be a circular waiting

26. What is a system resource-allocation graph (SRAG) in general?
A graph which shows the resources and processes, and the relationships among them.

27. List three overall strategies in handling deadlocks.
a. ensure system will never enter a deadlock state
b. allow deadlocks, but devise schemes to recover from them
c. pretend deadlocks don't happen

28. To avoid deadlock, what information do we need on the current process ?
Simplest scheme: each process declares the maximum number of resources it may need.

29. What is a safe state?
A set of resource allocations such that the system can allocate resources to each process (up to its max.) in some order, and still avoid a deadlock.

30. List the data structure needed for the banker's algorithm.
available vector: Available(m)
demand matrix: Max(n, m)
allocation matrix: Allocation(n, m)
needed matrix: Need(n, m)

31. Summarize the banker's algorithm.
If request for process i exceeds its need, error has occurred
If request of process i exceeds available resources, process i must wait.
The system temporarily allocates the resources process i wants; if the state is unsafe, the allocation is postponed.

32. How can we determine whether current state is "safe" in systems with only one instance of each resource type?
State is unsafe if any cycle exists

33. List three options for breaking an existing deadlock.
Violate mutual exclusion, risking data
Abort a process
Preempt resources of some process

34. What three issues must be considered in the case of preemption?
Select a victim to be preempted
Determine how far back to rollback the victim
Determine means for preventing that process from being "starved."

No comments: