#include <iostream>
#include <cstdlib>
#include <ctime>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <unistd.h>

#define SHM_KEY 1234
#define N 100

using namespace std;

int main() {
	int total=N*N;
	int shmSize=total*sizeof(int);
	
	//Create shared memory segment
	
	int shmId=shmget(SHM_KEY , shmSize , IPC_CREAT| 0666);
	if(shmId<0) {
		cout << "Error mem create " << endl;
		return 1;
	}

	int *matrix=(int *) shmat(shmId,NULL,0);
	
	for(int i=0; i<total; i++) {
		matrix[i]=rand()%100;
	}
	cout << "Shared mem id=" << shmId << endl;
	shmdt(matrix);
	return 0;
}
