From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fee84,f9703c6692149bd8 X-Google-Attributes: gidfee84,public From: hougen@cs.umn.edu (Dean Hougen) Subject: shared memory Date: 1997/10/18 Message-ID: <62963n$klq@epx.cis.umn.edu>#1/1 X-Deja-AN: 282030353 Summary: Me or DU? Organization: Computer Science Department, University of Minnesota Newsgroups: comp.unix.osf.osf1 Is it me, or is it DU4.0b? (It could well be me; I haven't done much shared memory stuff in the past.) I want to create two shared memory areas for several processes to share. I use the following code: /* create shared memory for use as a buffer */ buffer_size= sizeof(item)*num_b; if (buffer_id= shmget (IPC_PRIVATE, buffer_size, SHM_FLAGS) == -1){ printf ("Failed to open shared memory for buffer\n"); exit(-1); } if ((buffer_ptr = (char *) shmat (buffer_id, 0, 0)) == (char *) -1){ printf ("Failed to assign shared memory pointer for buffer\n"); exit(-1); } /* create shared memory for counting */ count_size= sizeof(production); if (count_id= shmget (IPC_PRIVATE, count_size, SHM_FLAGS) == -1){ printf ("Failed to open shared memory for counter\n"); exit(-1); } if ((count_ptr = (char *) shmat (count_id, 0, 0)) == (char *) -1){ printf ("Failed to assign shared memory pointer for counter\n"); exit(-1); } printf ("buffer_id is %d\t count_id is %d\n", buffer_id, count_id); When I run it, it tells me that both buffer_id and count_id are 0 and proceeds to garble things up. Shouldn't I be getting separate ID's for these two memory regions? I did the obvious workaround -- using one shared memory region for both purposes and using an offset for one pointer -- and everything works fine. I just don't understand why it won't let me use two separate regions. Thanks in advance for your 2^6 bits of advice. Dean Hougen -- "I've been dazed and confused for so long it's not true." - Led Zepplin