I have one process which creates semaphore with permission 600. Then at some part of the code I have line where this semaphore will be removed. Problem I have is that other processes in my program also try to execute this line of code. Of course since they dont have permission they wont be able to remove it but I would like only creator of this semaphore to be able to execute this line. Is there way to check if process have permission and if so remove semaphore if not just to move on and not execute this line.
What you are asking is not clear. The only time 600 helps is when the other processes are from another user in another group. And then they cannot do anything with the sempahore anyway, so it becomes pointless for most applications.
IMO, the real issue is: the only process that should ever be able to execute sem_init() or sem_destroy() must be the same one. The other processes should not have access to that code segment. i.e., after fork(), the child process code path does not have sem_destroy() in it. Any other plan means that one of the child processes could clobber the semaphore, the result being undefined.