From: hougen@cs.umn.edu (Dean Hougen)
Subject: shared memory
Date: 1997/10/18 [thread overview]
Message-ID: <62963n$klq@epx.cis.umn.edu> (raw)
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
next reply other threads:[~1997-10-18 4:00 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
1997-10-18 4:00 Dean Hougen [this message]
1997-10-18 4:00 ` shared memory Dirk Grunwald
-- strict thread matches above, loose matches on Subject: below --
1994-05-24 13:45 Shared Memory Gary Whitehead
1994-05-25 1:59 ` Chris Kevlahan
read-only archive
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox