Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <errno.h>
- #include <unistd.h>
- #include <sys/types.h>
- #include <sys/wait.h>
- #include <sys/stat.h>
- #include <sys/ipc.h>
- #include <sys/shm.h>
- #include <pwd.h>
- #include <stdlib.h>
- #include <string.h>
- #include <time.h>
- #include <sys/shm.h>
- #include <sys/sem.h>
- #include <sys/msg.h>
- #include <stdio.h>
- #include <sys/shm.h>
- #include <sys/sem.h>
- #define SEGSIZE 100
- int main ()
- {
- int id_ftok = ftok("1.c",129);
- int id_shmget = shmget(id_ftok, SEGSIZE, IPC_CREAT | 0660 );
- if (id_shmget == -1)
- perror("shmget");
- char *attach_segment = shmat(id_shmget, 0, 0);
- int procpid = fork();
- if(procpid == -1) exit(EXIT_FAILURE);
- if(procpid == 0) {
- /*tu kod potomka*/
- printf("W pamieci wspoldzielonej znajduje sie: %s\n", attach_segment);
- } else {
- /* tu kod rodzica*/
- strcpy(attach_segment, "przykladowy tekst");
- if(wait(0)==-1)
- perror("wait");
- if ( shmdt(attach_segment) == -1)
- {
- perror("shmdt");
- exit(-1);
- }
- if ( shmctl(id_shmget, IPC_RMID, NULL) == -1 )
- {
- perror("shmctl");
- exit(-1);
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment