Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <sys/types.h>
- #include <sys/ipc.h>
- #include <sys/shm.h>
- #include <stdio.h>
- #include <wait.h>
- #include <stdlib.h>
- #include <unistd.h>
- int main(void)
- {
- int key = 5678;
- int i = 65;
- /*
- * Create the segment.
- */
- int shmid;
- shmid = shmget(key, sizeof(int), IPC_CREAT | 0666);
- /*
- * Attach the segment to our data space.
- */
- int *shm;
- shm = shmat(shmid, NULL, 0);
- *shm = i;
- int pid = fork();
- //Son
- if (pid == 0){
- int reg = *shm;
- sleep(2);
- reg--;
- *shm = reg;
- exit(0);
- }
- //Father
- else{
- int reg = *shm;
- sleep(1);
- reg++;
- *shm = reg;
- }
- wait(NULL);
- printf("End --> valeur de shm: %d\n", *shm);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement