Help about shared memory

Mike Stroyan stroyan at hpfcdc.HP.COM
Wed Feb 17 08:03:21 AEST 1988


The problem is in the shmget call.  When a new segment is created, it
has permissions determined by the shmflg parameter.  Your shmget call
produced a shared memory segment with 000 permissions, so the shmat
call failed the permissions check.

Changing -
	if ((sid = shmget(IPC_PRIVATE,sizeof(mydat),IPC_CREAT)) < 0) {

to-
	if ((sid = shmget(IPC_PRIVATE,sizeof(mydat),IPC_CREAT | 0600)) < 0) {

will fix your program.

You should be careful to clean up any shared memory segments or semaphores
that your test programs leave around.  They will remain until you remove
them or the system is rebooted.  Since there aren't very many per system,
it is easy to run out if they aren't cleaned up.  You can see what exists
with the ipcs command and remove them with the ipcrm command.

Mike Stroyan, [hplabs!]hpfcla!stroyan



More information about the Comp.unix.questions mailing list