#include #include #include #include #include #include #include #include extern int errno; #define SIZE 1 char *detect_key; int shmid; int shared_init() { if((shmid = shmget(9999, SIZE, 0444)) < 0) { printf("Erreur dans shmget. Errno est : %d\n", errno); return -1; } if((detect_key = shmat(shmid, NULL, SHM_RDONLY)) < 0) { printf("Erreur dans shm attach. Errno est : %d\n", errno); return -1; } // detect_key = NULL; return 0; } void detect_hit() { char c; c = *detect_key; while(1) { if(c != *detect_key) { if(isalnum(detect_key[0])) { printf("detect_key est %s\n", detect_key); shmdt(detect_key); shmctl(shmid, IPC_RMID, NULL); exit(1); } else { printf("detect_key est %s\n", detect_key); } c = *detect_key; } } } int main() { if(shared_init() < 0) { printf("Problèmes avec la mémoire partagée\n"); exit(1); } detect_hit(); return 0; }