[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Semaphore lifecycle?



Thanks!

I will try the named semaphores.

And you are right, my quick sample did not have a loop.
But I use it in a "real program" that does not quit and then the effect is that only the semaphore disappears and the shared memory and the process does not.

Cheers
Christoph

On 26.04.20 11:50, Thomas Schmitt wrote:
Hi,

The semaphore should exists as long it is not
deleted or the OS restarts.
semget(2) and semctl(2) mention as explanation text sem_overview(7)
which is mainly about POSIX semaphores.

It promises persistence only for named semaphores:

   Persistence
     POSIX  named  semaphores  have  kernel  persistence:  if not removed by
     sem_unlink(3), a semaphore will exist until the system is shut down.

It fewly talks of sem*(2) calls:

   NOTES
     System V semaphores (semget(2), semop(2), etc.) are an older
     semaphore API.

It might be that the SysV variant has been re-implemented on base of
the POSIX variant and that traditional SysV persistence fell victim.
Or it might be that the usage pattern of IPC namespaces has changed
so that this statement of ipc_namespaces(7) gets into effect:

   When an IPC namespace is destroyed (i.e., when the last process that
   is a member of the namespace terminates), all IPC objects in the
   namespace are automatically destroyed.

The Linux man pages push people towards using POSIX semaphores. In your
use case probably towards named ones.


Also if I start the program with nohup and & it will stay executed.
By what loop inside ? The program you show will simply end after printing
its "OK" message.


Have a nice day :)

Thomas



Reply to: