Advertisement
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 <fcntl.h>
- #include <stdio.h>
- #include <sys/shm.h>
- #include <sys/sem.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <fcntl.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <unistd.h>
- #include <sys/wait.h>
- #include <string.h>
- struct sembuf op;
- char buf[11];
- int semid,wezel,i;
- int main() {
- semid = semget(10, 1, 0777| IPC_CREAT);
- if (semid == -1){
- perror("semget");
- exit(1);
- }
- wezel=open("kanal",O_RDONLY);
- if(wezel==-1) vperror("wezel: ");
- op.sem_flg = 0;
- op.sem_num = 0;
- op.sem_op = 1;
- if(semop(semid, &op, 1)==-1) perror("semop");
- for (i=0;i<10;i++){
- op.sem_flg = 0;
- op.sem_num = 1;
- op.sem_op = -1;
- if(semop(semid, &op, 1)==-1) perror("semop");
- if(read(wezel,buf,11)==-1) perror("read: ");
- printf("Odczytalem %s \n",buf);
- op.sem_flg = 0;
- op.sem_num = 0;
- op.sem_op = 1;
- if(semop(semid, &op, 1)==-1) perror("semop");
- }
- puts("KONIEC A");
- if(semctl(semid, 0, IPC_RMID, 1) !=0) perror("semctl: ");
- if(unlink("kanal") != 0) perror("unlink: ");
- return(0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement