Xref: utzoo comp.lang.c:32048 comp.unix.programmer:78 Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!rutgers!mephisto!prism!gt0178a From: gt0178a@prism.gatech.EDU (BURNS,JIM) Newsgroups: comp.lang.c,comp.unix.programmer Subject: Re: shared memory Message-ID: <13991@hydra.gatech.EDU> Date: 22 Sep 90 09:18:57 GMT References: <1990Sep21.183326.13116@DRD.Com> Followup-To: comp.lang.c Organization: Georgia Institute of Technology Lines: 78 in article <1990Sep21.183326.13116@DRD.Com>, mark@DRD.Com (Mark Lawrence) says: > shmat returns the address. You can't tell it where you want it. Then Machine dependent. > /* > +----------------------------------------------------------------- > | declarations of scope process > */ > extern int errno; /* system call err status */ > extern const char *strerror(int); I had more compile troubles w/this last line then any other in the program. I had to substitute: extern char *sys_errlist[]; and for: fprintf(stderr, "\n%s: Fatal error from %s, %s\n", who, what, strerror(errno));*/ in CrynDie, I had to substitute: fprintf(stderr, "\n%s: Fatal error from %s, %s\n", who, what, sys_errlist[errno]); to get it to compile and load on Dynix, SunOS 4.0.3, A/UX 1.1, & Ultrix 4.0. > * The CreateShMem function is to be called only by one process at system > * startup. It will create shared memory for the system. That process must > * then AttachShMem. All other processes must use the AttachShMem function > * only which will get and attach shared memory. [...] > if ((shmid = shmget(SHMEM_k, sizeof(SHMEM), > IPC_CREAT | SHMEM_PERMISSION)) == -1) [...] > memset((char *) pshmem, '\0', sizeof(SHMEM)); Just to avoid misunderstandings, these instructions are correct NOT because of the way he's calling shmget(2), but simply because he's initializing the shm seg. (Of course, he's also immediately doing a shmdt(). ) It would only be an error to call shmget(2) w/IPC_CREAT or'd in w/SHMEM_PERMISSION in the 2nd process if it ALSO had IPC_EXCL or'd in as well, as the man pages on the above systems state. I mention this because some systems guarantee that the first shmat() will zero out the shm seg. From the HP 9000/800 HP-UX Real Time Programmers Manual: [example program omitted] "Note that the fields of the tallytab entries that were not written in subroutine write_and_read_shm() have values of 0. This is because the first shmat called (by any process) on that shared memory identifier will zero out all of the contents of shared memory." I have not seen this documented in the man pages of the other above systems, altho' a simple: main() { CreateShMem("main"); /* I commented out the memset in here */ AttachShMem("main"); printf("%d %f %d %f\n",Psh->foo,Psh->bar,Psh->gex,Psh->snark); printf("%d\n",shmctl(shmid,IPC_RMID,0)); printf("main exiting\n"); exit(0); } added to the end of the posted subroutines shows all zeroes on A/UX and Ultrix. Anybody know if this is standard? -- BURNS,JIM Georgia Institute of Technology, Box 30178, Atlanta Georgia, 30332 uucp: ...!{decvax,hplabs,ncar,purdue,rutgers}!gatech!prism!gt0178a Internet: gt0178a@prism.gatech.edu