Enforce exclusive order of four processes using semaphores
Programs exit instead of wait

Right now, your programs check their semaphore, but if they don't find the value they are expecting, they exit instead of wait.  I think that you should modify your programs to wait until the previous program signals them.  You would need to make the following modifications:


In program #0, initialize each semaphore to the value 1.
In each other program, use semop() to wait for its semaphore to reach value 0.  For example, program #1 waits for semaphore #0's value to become 0, using semop().
Modify each program to actually take a non-zero amount of time to do its work.  I suggest a for loop like this:

for (int i=0;i&lt;10;i++) {
    printf("Executing process #1, iteration #%d.\n", i);
    sleep(1);
}

After each program's work loop, it releases its semaphore using semop().  This causes the semaphore value to transition from 1 to 0, which allows the next program to run.  For example, program #1 releases semaphore #1, causing program #2 to be able to run.
Program #3 cleans up instead of releasing a semaphore.