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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:46:35+00:00 2026-05-27T04:46:35+00:00

I have to synchronize N client processes with one server. These processes are forked

  • 0

I have to synchronize N client processes with one server. These processes are forked by a main function in which I declared 3 semaphores. I decided to use POSIX semaphores but I don’t know how to share them between these processes. I thought that shared memory should work correctly, but I have some questions:

  • How can I allocate the right space of memory in my segment?
  • Can I use sizeof(sem_t) in size_t field of shmget in order to allocate exactly the space I need?
  • Does anyone have some examples similar to this situation?
  • 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-27T04:46:36+00:00Added an answer on May 27, 2026 at 4:46 am

    It’s easy to share named POSIX semaphores

    • Choose a name for your semaphore

      #define SNAME "/mysem"
      
    • Use sem_open with O_CREAT in the process that creates them

      sem_t *sem = sem_open(SNAME, O_CREAT, 0644, 3); /* Initial value is 3. */
      
    • Open semaphores in the other processes

      sem_t *sem = sem_open(SEM_NAME, 0); /* Open a preexisting semaphore. */
      

    If you insist on using shared memory, it’s certainly possible.

    int fd = shm_open("shmname", O_CREAT, O_RDWR);
    ftruncate(fd, sizeof(sem_t));
    sem_t *sem = mmap(NULL, sizeof(sem_t), PROT_READ | PROT_WRITE,
        MAP_SHARED, fd, 0);
    
    sem_init(sem, 1, 1);
    

    I haven’t tested the above so it could be completely bonkers.

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

Sidebar

Related Questions

I have a client application that communicates with a server. In this application the
I have a function that calls jQuery's pulse function. I use it on a
My requirement is I have server J2EE web application and client J2EE web application.
I am using gemfire and currently have a client and a server. Now, the
A client has a Windows based in-house server, on which they edit the contents
I have a IIS-Hosted WCF service running on one server and a windows service
I have this problem when i try to synchronize a observable list with listbox/view
I have a database which is synchronized against an external web source twice a
Have you ever seen any of there error messages? -- SQL Server 2000 Could
Amazon Integration I have my own CMS which has a file manager. A lot

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.