0

if a process goes down after decrementing the value of semaphore from 1 to 0, as per my understanding the value of semaphore remains as 0.

If the same process comes up again and tries to re-acquire the same semaphore, it will block for ever.

Is there a way to reset the semaphore value to 1 after decrementing it if my process goes down abnormally?

1 Answer 1

1

I assume you are using the standard semctl()/semop() API for the semaphores.

There is a flag available called SEM_UNDO that will tell the kernel to reset the semaphore's value if your process terminates. You need to use this in your semop( ) calls.

More information here : http://beej.us/guide/bgipc/output/html/multipage/semaphores.html

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.