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 7528183
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T04:18:28+00:00 2026-05-30T04:18:28+00:00

I am working on a program by C that some processes need to access

  • 0

I am working on a program by C that some processes need to access a shared memory on an embed linux. This shared memory needs to be initialized when it was created. Any process attaching to this memory may crash. When it restarted (may be by linux INIT), it must not initialize the shared memory again since other processes are using it. How to tell if current starting of the process that is creating shared memory is the first time or restarted. I came up with an idea that allocates a integer in shared memory where will be written as a number like 5678956 (any number other than ffffffff or 00000000) to claim this memory has been initialized. But I am not sure if this is working well since the critical data is storing this memory. Any advice would be appreciated. Thanks.

  • 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-30T04:18:30+00:00Added an answer on May 30, 2026 at 4:18 am

    You should use both a shared semaphore and shared memory segment. Attempt opening the semaphore with sem_open using O_EXCL|O_CREAT and an initial value of 0. If that succeeds, create and initialize the shared memory segment, then post the semaphore and close it. If opening the seamphore in exclusive mode failed, open it non-exclusive and wait on the semaphore, then close it.

    Another solution, if you prefer: Use a named file in the filesystem with mmap and MAP_SHARED for your shared memory. First create the file with a temporary name and populate it with the initial data it should contain. Then attempt to link it to the real name. If link fails with EEXIST, you’re not the first process, and you can just delete your temp file and open and map the existing one. If link succeeds, you are the first process.

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

Sidebar

Related Questions

I'm working on a Google App Engine program that will require some basic spell
I am working on a program that needs to create a multiple temporary folders
I'm working on a program that processes many requests, none of them reaching more
I'm working on a program that searches entire drives for a given file. At
I'm working on a program that uses PHP's internal array pointers to iterate along
I'm working on a program that will tell what level a programmer is at
I am working on a program that encodes a file based on a supplied
I'm working on a program that will sort files based on extension I currently
I'm working on a program that reads in users input as a string, which
I'm working on a program that asks for input, then calculates and posts the

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.