HPE GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Common Variable for Child Process
Operating System - HP-UX
1833729
Members
2370
Online
110063
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
Discussions
Forums
Discussions
back
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
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
Go to solution
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
03-10-2004 07:30 AM
03-10-2004 07:30 AM
Hi Friends. I have a server in gcc. This server forks in 8 child process. How I can declare a variable coomon to all process: I means, if child process 1 changes its value, the other 7 process can see this new value.
Thanks,
Thanks,
alfonsoarias
Solved! Go to Solution.
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2004 07:36 AM
03-10-2004 07:36 AM
Re: Common Variable for Child Process
Well, what you are talking about can be done if you use (actually misuse) vfork() rather than fork() but it depends upon the particular UNIX implementation. In any event, if that technique works, it works by accident and is NOT the way to do it.
The proper way to do this is to create a sharem memory shmment to which each process attaches. You should also make certain that a clean-up signal handler is in place to remove the shmid when all the processes using it terminate.
Man shmget,shmctl,shmat,ftok for details.
The proper way to do this is to create a sharem memory shmment to which each process attaches. You should also make certain that a clean-up signal handler is in place to remove the shmid when all the processes using it terminate.
Man shmget,shmctl,shmat,ftok for details.
If it ain't broke, I can fix that.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2004 09:51 AM
03-10-2004 09:51 AM
Solution
I should also add that typically, in addition to shared memory, you also have to somehow ensure that only 1 process is changing a value at any one time. For this you need semaphores. Man semget, semop, and semctl for these issues.
If it ain't broke, I can fix that.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2004 09:09 AM
03-18-2004 09:09 AM
Re: Common Variable for Child Process
Another technique is instead of creating 7 proccess, create 7 threads. Then the global memory is accessible from each thread. You will still need to protect this using a mutex. Much faster than semaphors and forking... see man pages, pthread_create, pthread_mutex_lock, pthread_mutex_unlock, pthread_cond_wait, pthread_cond_broadcast, pthread_cond_signall....etc...See Stevens or any primer on producer consumer problems. Also workq algorithm may be a good approach.
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 2025 Hewlett Packard Enterprise Development LP