Currently, I faced some difficulty dealing with the above semaphores.
There are three processes that are trying to access a common resource. The access of this common resource is controlled with the use of System V IPC-Semaphores (with undo facility).
The problem that I faced is as follows
Process 1 is currently accessing the common resource say at 00:00:00 (semphore is locked). Process 2 at 00:00:45 is trying to access the resource followed by Process 3 at 0:02:50 is trying to access too. The problem is why Process 3 get the resource instead of Process 2 at 0:04:10. On top of that, when Process 1 retries, it manages to get the resource back at 0:05:45. Process 2 only manage to get the resource at 0:07:00.
The above processes are running in the same priority (not set).
The system that the processes are run on is DEC ALPHA OSF/3
I have tried using the scheduler to set a higher priority for process 2 but results in the kernel allocating too much timeslice for process 2 and this is undesirable.
My questions are :
1. Why Process 3 get the resource instead of Process 2?
2. Isn't it the access of semaphores FIFO
3. If Process 2 loses its timeslice, why it only manage to get it back after 7 minutes?
4. Is there any way that every process has a equal chance to access the resource? That is, the first to request will be the first to get it.
Urgently requires some advice!!!