#include <sys/types.h>
#include <sys/shm.h>
#include <sys/ipc.h>
#include <time.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>

#define SLEN 9000
#define KEY 4242
int main() {
  int hdl;
  void *vp1;
  key_t key;
  struct shmid_ds shminfo;
  
  key = KEY;         /* Huh */
  printf("Der Key: %x\n", key);
  hdl = shmget(key, SLEN, 0660 | IPC_CREAT);
  printf("Die SHM ID: %d\n", hdl);

  vp1 = shmat(hdl, NULL, 0);

  /* return PID for checking */
  printf("My Pid is: %d\n", getpid());
  fflush(stdout);

  /* write into SHM Segment */
  strncpy((char*)vp1, "Hallo Welt", 11);

  sleep(30);

  shmdt(vp1);
  shmctl(hdl, IPC_RMID, &shminfo);
  return(0);
}
