some-usable-scripts/C_Language/TP_SYS/tp_sema/producteur.c

32 lines
774 B
C
Raw Normal View History

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>
#include "constantes.h"
#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-20 01:03:54 +01:00
MEMP *memoireP;
int shmid;
int shm_key = atoi(argv[1]);
if(shm_key == -1) { printf("Usage %s numIPC message\n", argv[0]); exit(EXIT_FAILURE); }
2011-03-17 16:37:36 +01:00
2011-03-20 01:03:54 +01:00
/* création ou lien avec une memoireP partagée */
shmid = shmget(shm_key, 100, 0700 | IPC_CREAT);
if (shmid == -1) { perror("shmget"); return (EXIT_FAILURE); }
2011-03-17 16:37:36 +01:00
/* montage en mémoire */
2011-03-20 01:03:54 +01:00
memoireP = shmat(shmid, NULL, 0);
2011-03-17 16:37:36 +01:00
/* utilisation */
2011-03-20 01:03:54 +01:00
// printf("memoireP[0] = %d\n", memoireP[0]++ );
2011-03-17 16:37:36 +01:00
return (EXIT_SUCCESS);
}