Answer:
a) Yes Operating System can detect that a blocked process is waiting for an event that will never occur.
b) Operating System can make sure that all the resources have been released before a process can enter a blocked state.
Explanation:
a) The situation in which the process block itself to wait for an event that will never occur is called deadlock.
Operating system keeps checking the system for deadlocks and can detect a process that is in deadlock.
For example Operating System uses resource allocation graph to detect if there is a cycle in the system and this way it detects a blocked process or a process in deadlock state. This is how OS checks the reason for the process to get blocked and also it also examines if that process will get the resource ever. The even here can be a resource that a process wants to use. So OS keeps checking the allocation of resources against each process to detect any such blocked process and also checks the availability of resources.
b) To prevent the processes to reach a deadlock state the OS can eliminate a condition called hold and wait. So the OS allocates all the resources that are needed by a process before the execution begins. Secondly if the process needs a resource, it cannot be allocated unless the process releases all its current acquired resources. Another way to prevent deadlock is to preempt resources from a process and allocate that resource to a process which has a higher priority.
One way to prevent processes from waiting for an event that will never occur is to make sure that no cycle is formed. So the processes are given a number that represents the priority of each process. So the resources are allocated according to the priority levels of these processes and also processes can request resources according to their number.
So the resources request can only be processed if the system does not end up in dead lock.