From 04bdb3700f7047e115a89b7c8e94265c8c1f0e85 Mon Sep 17 00:00:00 2001 From: KaneRoot Date: Fri, 11 Mar 2011 00:30:01 +0100 Subject: [PATCH] First entry with IPC posix (shared memory) --- C_Language/IPC_shm_posix.c | 44 +++++++++++++++++++++++++ C_Language/TP_SYS/Exemple_curses/a.out | Bin 7579 -> 0 bytes 2 files changed, 44 insertions(+) create mode 100644 C_Language/IPC_shm_posix.c delete mode 100755 C_Language/TP_SYS/Exemple_curses/a.out diff --git a/C_Language/IPC_shm_posix.c b/C_Language/IPC_shm_posix.c new file mode 100644 index 0000000..102fd52 --- /dev/null +++ b/C_Language/IPC_shm_posix.c @@ -0,0 +1,44 @@ +#include +#include +#include +#include +#include +#include +#include + +int main( int argc, char **argv) +{ + int fd; + int * compteur; + + if(argc != 2) + { + fprintf(stderr, "Syntaxe : %s nom_segment\n", argv[0]); + exit(EXIT_FAILURE); + } + if((fd = shm_open(argv[1], O_RDWR | O_CREAT, 0600)) == -1) + { + perror(argv[1]); + exit(EXIT_FAILURE); + } + if(ftruncate(fd, sizeof(int)) != 0) + { + perror("ftruncate"); + exit(EXIT_FAILURE); + } + compteur = mmap(NULL, sizeof(int), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); + + if(compteur == MAP_FAILED) + { + perror("mmap"); + exit(EXIT_FAILURE); + } + while(1) + { + (* compteur)++; + fprintf(stdout, "compteur = %d\n", (* compteur)); + sleep(1); + } + return EXIT_SUCCESS; +} + diff --git a/C_Language/TP_SYS/Exemple_curses/a.out b/C_Language/TP_SYS/Exemple_curses/a.out deleted file mode 100755 index 8e8c115e68af37501b02a0129cec537bd25c0789..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 7579 zcmeHMe{ft?6~3EnODe&pp_GVGc5n;rK({HRg;pKYCfg>kO+u3vutQ%ryDxcbH@k87 zZPPksOlK|4nqJf!(Sm6QQD?uQ(7B`}FH+9t`syr8E)B?O82MU9eIFBGEsNB$~O z6Eeg>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