Is semaphore an IPC mechanism?
Yes, under many platforms semaphores can synchronize across processes. You would use "named" semaphores for this -- multiple processes access the object via a name, similar to filesystem objects.
In POSIX, you can create named semaphores via sem_open()
. For unamed semaphores, if the second parameter to sem_init()
is nonzero, it can be interprocess, though I'm not sure exactly how an unnamed interprocess semaphore is supposed to work.
Note that on some systems these functions may fail with ENOSYS
if interprocess semaphores aren't supported (for example OpenBSD).
In Windows, you can create named semaphores via CreateSemaphore()
as @sergiom has mentioned.