GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: sem_wait and forked processes
Operating System - HP-UX
1847885
Members
5076
Online
104021
Solutions
Forums
Categories
Company
Local Language
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Forums
Discussions
back
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-09-2002 05:12 AM
08-09-2002 05:12 AM
sem_wait and forked processes
Do shared semaphores work in user programs under HPUX 11.00?
Scenario:
Daemon creates semaphore using sem_init(sem, 1, 1) and grabs it using sem_wait OK.
Forks a child.
Child waits on the semaphore (sem_wait) until parent says "ready to go".
Parent does some work and releases the semaphore (sem_post) to inform the child to continue (execv a program).
Under HPUX, the child never wakes up ... sits on the sem_wait indefinitely.
I suspect that the fork is creating a brand new private copy of the semaphore (whilst in the locked_by_parent state) and so is never being cleared (i.e., it is not really a shared semaphore after all). Any ideas please?
Scenario:
Daemon creates semaphore using sem_init(sem, 1, 1) and grabs it using sem_wait OK.
Forks a child.
Child waits on the semaphore (sem_wait) until parent says "ready to go".
Parent does some work and releases the semaphore (sem_post) to inform the child to continue (execv a program).
Under HPUX, the child never wakes up ... sits on the sem_wait indefinitely.
I suspect that the fork is creating a brand new private copy of the semaphore (whilst in the locked_by_parent state) and so is never being cleared (i.e., it is not really a shared semaphore after all). Any ideas please?
1 REPLY 1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-15-2002 04:59 AM
08-15-2002 04:59 AM
Re: sem_wait and forked processes
In case anyone else hits this problem, it appears to be solved by using mmap to explicitly allocate the memory for the semaphore as "shared" ...
sem_t *sem;
void *shmemblk;
...
shmemblk = mmap(NULL, sizeof(sem_t)
, PROT_READ | PROT_WRITE
, MAP_SHARED | MAP_ANONYMOUS
, -1, 0)
...
sem = (sem_t *) shmemblk;
...
sem_init(sem, 1, 1)
...
Many thanks to Andy Bennett (HP) for this information.
sem_t *sem;
void *shmemblk;
...
shmemblk = mmap(NULL, sizeof(sem_t)
, PROT_READ | PROT_WRITE
, MAP_SHARED | MAP_ANONYMOUS
, -1, 0)
...
sem = (sem_t *) shmemblk;
...
sem_init(sem, 1, 1)
...
Many thanks to Andy Bennett (HP) for this information.
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
Company
Events and news
Customer resources
© Copyright 2026 Hewlett Packard Enterprise Development LP