Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //link soal : https://www.dropbox.com/s/mbcwtg81dvfa9gc/O1-T0316-RG01-07.pdf?dl=0
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <sys/ipc.h>
- #include <sys/shm.h>
- #include <sys/sem.h>
- #include <sys/types.h>
- struct data{
- char phone_name[100];
- int quantity;
- };
- int main(){
- int flag=0;
- struct sembuf tes;
- int hId=shmget(123456, sizeof(struct data),IPC_CREAT|0666);
- int eId=semget(123456,1,IPC_CREAT|0666);
- struct data *hp=(struct data *)shmat(hId,NULL,0666);
- semctl(eId,0,SETVAL,0);
- do{
- do{
- flag=0;
- printf("Masukan Merek HP[Nokia|Samsung|Apple][\"exit\" to close the program]: ");
- scanf("%[^\n]",hp->phone_name);
- getchar();
- if(strcasecmp(hp->phone_name,"nokia")==0||strcasecmp(hp->phone_name,"samsung")==0||strcasecmp(hp->phone_name,"apple")==0)
- flag=1;
- else if(strcmp(hp->phone_name,"exit")==0)
- break;
- }while(flag==0);
- if(strcmp(hp->phone_name,"exit")!=0){
- do{
- flag=0;
- printf("Masukan Jumlah HP[1...8]: ");
- scanf("%d",&hp->quantity);
- getchar();
- if(hp->quantity>0&&hp->quantity<9)
- flag=1;
- }while(flag==0);
- }
- tes.sem_num=0;
- tes.sem_op=1;
- tes.sem_flg=0;
- semop(eId,&tes,1);
- printf("press enter...");
- getchar();
- }while(strcmp(hp->phone_name,"exit")!=0);
- shmdt(&hp);
- shmctl(hId, IPC_RMID, 0);
- semctl(eId, 0, IPC_RMID);
- return 0;
- }
- // cd Desktop/UAP/AK
- // gcc lat02_quiz2_client.c -o c2
- // gcc lat02_quiz2_server.c -o s2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement