2011-03-17 16:37:36 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/ipc.h>
|
|
|
|
#include <sys/shm.h>
|
2011-03-17 16:49:20 +01:00
|
|
|
#include "constantes.h"
|
2011-03-17 16:57:53 +01:00
|
|
|
#include "types.h"
|
2011-03-17 16:37:36 +01:00
|
|
|
#include "sema.h"
|
|
|
|
|
|
|
|
int main( int argc, char **argv)
|
|
|
|
{
|
2011-03-17 17:31:26 +01:00
|
|
|
if(argc < 2) { printf("Usage %s numIPC\n", argv[0]); exit(EXIT_FAILURE); }
|
2011-03-17 16:37:36 +01:00
|
|
|
int *zone;
|
|
|
|
int memid;
|
|
|
|
int clef = atoi(argv[1]);
|
|
|
|
if(clef == -1) { printf("Usage %s numIPC message\n", argv[0]); exit(EXIT_FAILURE); }
|
|
|
|
|
|
|
|
/* création ou lien avec une zone partagée */
|
|
|
|
memid = shmget(clef, 100, 0700 | IPC_CREAT);
|
|
|
|
if (memid == -1) { perror("shmget"); return (EXIT_FAILURE); }
|
|
|
|
|
|
|
|
/* montage en mémoire */
|
|
|
|
zone = shmat(memid, NULL, 0);
|
|
|
|
|
|
|
|
/* utilisation */
|
|
|
|
printf("zone[0] = %d\n", zone[0]++ );
|
|
|
|
|
|
|
|
return (EXIT_SUCCESS);
|
|
|
|
|
|
|
|
}
|