|
The contents of this page are licensed under the following license
Operating System
IPC shared memory |
#include <stdio.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <sys/types.h>
#include <stdlib.h>
#define BUFSIZE 100
main()
{
int id;
int foo;
int *buf;
/* create shared memory */
id = shmget(1234, BUFSIZE*sizeof(int), IPC_CREAT|0600);
if (id == -1)
{
perror("Error create shared memory");
exit(1);
}
/* attach shared memory segment */
buf = (int*)shmat(id, NULL, 0);
if (buf == NULL)
{
perror("Error shared memory operation");
}
/* get memory elements */
for (foo = 0; foo < 1000; foo++)
{
printf("[%d] = ( %d )\n", foo, buf[foo % BUFSIZE]);
}
}
|
August, 23rd 2006
© Michał Kalewski