some-usable-scripts/c/semaphores_manuel_exemples/Exemples_semaphores/lireZ.c

31 lines
609 B
C
Raw Permalink Normal View History

2011-03-10 14:08:58 +01:00
/* Mecanismes de communication entre processus - IPC */
/* Lecture d'une zone de m<>moire partag<61>e */
#include <stdio.h>
#include <stdlib.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <sys/types.h>
#define SHMEM_SIZE 256
#define SHMEM_RIGHTS 0x01ff
int main(int argc, char ** argv){
long * ptz ;
int ipc_result, ipc_key ;
if (argc<2)
exit(1) ;
ipc_key = atoi(argv[1]) ;
ipc_result = shmget(ipc_key, 0 , 0) ;
ptz = (long *) shmat(ipc_result,0,SHMEM_RIGHTS) ;
printf("\n Valeur dans la zone partagee : %d \n\n", *ptz) ;
exit(0) ;
}