Assume you have two processes, P1 and P2. P1 has a high priority, P2 has a low priority. P1 and P2 have one shared semaphore (i.e., they both carry out waits and posts on the same semaphore). The processes can be interleaved in any arbitrary order (e.g. P2 could be started before P1).
Briefly explain whether the processes could deadlock when:
ii. both processes run on a Linux system as time sharing tasks
iii. both processes run on a Windows 7 system as variable tasks
iv. both processes run on a Windows 7 system as real-time tasks.
I think P1 and P2 can only result in priority inversion. According to one of the requirements of deadlock(Circular wait: there is a circular chain of two or more processes, waiting for a resource held by the other processes ), priority inversion is not equal to deadlock. Besides, P1 and P2 only have 1 semaphore, which means there will be no circular, so they will never cause deadlock. Therefore, all the answers will be no. Is that correct? If not, then what's the answer?
You are correct, no deadlock is possible with only one semaphore.
Deadlock for two processes can happen only if P1 holds some resource needed by P2 and requires resource held by P2. So P1 can't proceed until P2 releases resource and P2 can't proceed until P1 releases resource. Thus they are both stuck waiting for each other, but not letting each other move forward. As you already mentioned, circular wait condition can't be fulfilled with one semaphore.
Also, P1 waiting for P2 to free resource isn't a priority inversion. Priority inversion happens, when Px has priority between P1 and P2 and P1 waits for P2 to free resource, while P2 waits for Px, because it has higher priority. So P1 waits for Px with lower priority despite it wasn't meant to (no shared resources or anything else).