'How to establish semaphore between two different files and synchronize data

I am currently working on semaphore concepts ,. I Have two files I have to share data between two files Eg : application1.c It increments one value and shares the value to shared memory application2.c Reads data from shared memory

I just established the shared memory and it's working If am increment value and share it to shared memory the second (application 2.c) can able to read the data, but the thing is synchronisation, I have to use semaphore for that it's requirement , Can anyone please help me to solve this problem?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source