Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3932502
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T23:27:58+00:00 2026-05-19T23:27:58+00:00

I googled this for the past two weeks and I didn’t get any answer.

  • 0

I googled this for the past two weeks and I didn’t get any answer. This is what I have:

  • A parent process, which creates a struct myStruct that is basically a linked list using pointers (if this is a major issue, I can accept to use a fixed size array instead).

  • A fixed number of child processes created with fork() that need a read/write access to the struct (or array) created by the parent.

I don’t know how to do in order to make the variable myStruct become shared between processes.

I tried to solve the problem using SysV IPC functions like shmget(), shmat(), etc… in order to allocate my variable in shared memory, but I don’t know how to work with void memory pointers to read/write the values into myStruct.

Ideally, I would like to be able to use the dot notation (myStruct.node)->attribute = value in every process without having to deal with pointers, since I don’t know how my struct is organized into memory.

Is that possible? Could some of you please help? Any help is REALLY appreciated.

Further note: I know using threads, pipes, sockets or things like that would be much easier, but this work is for academic purposes for which I have to simulate the presence of multiple independent processes.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T23:27:58+00:00Added an answer on May 19, 2026 at 11:27 pm

    If you create a shared anonymous mapping with:

    p = mmap(NULL, length, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_ANONYMOUS, -1, 0);
    

    Then these pages will not be copied-on-write, but rather will be shared by all forked processes.

    Note that you have to be careful with locking here. You can use standard pthread mutexes and condvars on the shared memory segment between processes if (and only if!) you use pthread_mutexattr_setpshared and pthread_condattr_setpshared to mark them as shared between processes.

    Note also that this technique maps a fixed size arena, and must be done before forking. How you manage the contents of the memory at p is up to you. It’s nontrivial to create a resizable shared memory arena; if you want to go that route, I’d recommend posting a second question, as different approaches may be necessary.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have googled this a little and didn't really find the answer I needed.
I am new to Emacs. I have googled this but no good answer there.
I have Googled this quite a bit in the past hour. I am working
I googled this and it seems that no one has an answer, yet it
I'm at wits end now, I have googled this to death and found nothing.
I am sure I am just missing something. But I have googled this for
Googled for this to no avail. Didn't find anything in the API either. I
I have already googled for this I have a Table with following structure in
I have been crawling Google for the past hour for a solution to this
I have been having a really hard time debugging this error since the past

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.