Find the answer to your Linux question:
Results 1 to 2 of 2
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    Are shared memory pointers valid through different processes?

    I have a process that creates, open and attach a shared memory region in main().Then, I fork() that process ant I find i CAN directly use the inherited shared pointer in the child process and access shared memory objects mapped in main.
    It seems that,lets say, ptr=0x4f5000e in child process points to exactly the same shared memory region that it points in father process.
    I would expect having to re-attach to same shared memory segment in my second process, but it seems is not needed.
    Although this works, Im not sure if not doing that re-attach would raise some problems when i put a C++ object in shared memory.
    Should i attach child process to shared memory segment ? .If not, is that safe?

    Thank you

  2. #2
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    This should be save between forked processes. Another non-forked process will have to attach the shared memory segment separately as far as I understand. Read the man page on the fork() function for details as to which items are sharable between the processes. Some items are, and some are not.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts