How to use named mutex at linux?

2019-06-09 17:49发布

问题:

I'd like to use named mutex at linux for multi process.

I searched at google and find some APIs. But, it's hard to break out the coding. I found two apis and it looks set name and be shared between processes.

pthread_mutexattr_setname_np
pthread_mutexattr_setpshared(&mtx_attr, PTHREAD_PROCESS_SHARED);

Could somebody give me hint or example?