shared memory
BURNS,JIM
gt0178a at prism.gatech.EDU
Sat Sep 22 19:18:57 AEST 1990
in article <1990Sep21.183326.13116 at DRD.Com>, mark at 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 at prism.gatech.edu
More information about the Comp.unix.programmer
mailing list