[comp.unix.questions] how to use the System V shared memory feature

root@psddevl.UUCP (root) (01/21/88)

I am trying to use the shared memory scheme to overlay a process's own
data space. However, I keep on getting the 'invalid argument' error.
My program is as follows:

#include <stdio.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#define SHMKEY	(key_t)0*10
char shm[1024*20] = '0';
main()
{
	char *shmat();
	int shmid;
	if ((shmid = shmget(SHMKEY,sizeof(shm), 0600|IPC_CREAT|IPC_EXCL)) < 0)
		exit(1,perror("shmget"));
	if (shmat(shmid, (char *)shm, 0) == ((char *) -1))
		exit(2,perror("shmat"));
}

Forcing the address of shm to be a multiple of 4K still does not work.
(4K is the page size on my machine.)

Any suggestions as to what I have done wrong will be deeply appreciated.
Please send comments to {dciem,utzoo}!psddevl!nelson.
My phone number is (416)452-3158.