delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2004/06/03/14:16:53

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Message-ID: <380-22004643181831593@hedden.us>
Reply-To: jdhedden AT 1979 DOT usna DOT com
From: "Jerry D. Hedden" <jerry AT hedden DOT us>
To: cygwin AT cygwin DOT com
Subject: BUG: shmget() [was RE: shmget() not working(?)]
Date: Thu, 3 Jun 2004 14:18:31 -0400
MIME-Version: 1.0
X-IsSubscribed: yes
X-MIME-Autoconverted: from quoted-printable to 8bit by delorie.com id i53IGl0u027036

shmget() is not able to 'find' an existing shared memory segment
unless the 'flags' argument is set to '0'.  This is a bug.  If
flags = 0666 (or at least compatible with the permissions set
when the segment was created), it should still be able to find
and use the segment.

The test program:

#include <sys/shm.h>
#include <errno.h>

#define CHLD_MODE 0666

int
main(int argc, char **argv)
{
    int pid = fork();
    int id;

    if (pid == 0) {
        sleep(5);
        id = shmget(1, 100, CHLD_MODE);
        printf("child (%d): %d (%d)\n", getpid(), id, errno);
    } else {
        id = shmget(1, 100, IPC_CREAT | 0666);
        printf("parent (%d): %d (%d)\n", getpid(), id, errno);
        sleep(10);
        shmctl(id, IPC_RMID, 0);
    }

    return (0);
}

Produces the following output:

parent (35492): 196609 (0)
child (3876): 0 (0)

This shows that:
1.  The parent created the shared memory segment and got back its
ID (196609).
2.  The child process tried to attach to the parent's shared memory
segment (using the same key = 1), but shmget() returned 0 with no
error!

However, if CHLD_MODE is set to 0 in the code above, then:

parent (34084): 393216 (0)
child (11232): 393216 (0)

Which shows that the child did find the parent's shared memory
segment.
=====
Jerry D. Hedden
<< If you're not having fun, then you're not doing it right! >>


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019