Inter process Communication(IPC) client Server Code Operating System Problem
Inter process Communication Client Code using C language
- Interprocess Communication for Producer Consumer problem in UNIX (Pipes or Shared Memory)
- Students must submit the term work in the form of journal.
- Each assignment has to be well documented with problem definition, theory and code documentation.
- Staff in charge will assess the assignments continuously and grade or mark each assignment on completion date declared for each assignments.
IPC Client Code using C language
1 |
#include <br/> #include <br/> #include <br/> #include <br/> #define SIZE 124 <br/> int main() <br/> { <br/> char *buff,*str; <br/> buff=(char*)malloc(124); <br/> str=(char*)malloc(124); <br/> *str='\0'; <br/> int shmid,i=0; <br/> if((shmid=shmget(9999,SIZE,IPC_CREAT|0666))<0) <br/> printf("\nERROR IN SHMID\n"); <br/> if((buff=shmat(shmid,NULL,0))<0) <br/> printf("ERROR IN SHM ATTACH\n"); <br/> while(1) <br/> { <br/> if(*str!='\0') <br/> { <br/> printf("\nTHE SERVER JUST SEND THIS MESSAGE\n\n"); <br/> fputs(str,stdout); <br/> break; <br/> } <br/> strncpy(str,buff,SIZE); <br/> } <br/> *str='\0'; <br/> *buff='\0'; <br/> printf("\nREPLY \n\n"); <br/> fgets(str,SIZE,stdin); <br/> strncpy(buff,str,SIZE); <br/> sleep(1); <br/> *buff='\0'; <br/> return(0); <br/> } <br/> Server <br/> #include <br/> #include <br/> #include <br/> #include <br/> #define SIZE 124 <br/> int main() <br/> { <br/> char *buff,*str; <br/> buff=(char*)malloc(124); <br/> str=(char*)malloc(124); <br/> int shmid; <br/> if((shmid=shmget(9999,SIZE,IPC_CREAT|0666))<0) <br/> printf("\nERROR IN SHMID\n"); <br/> if((buff=shmat(shmid,NULL,0))<0) <br/> printf("ERROR IN SHM ATTACH\n"); <br/> printf("\nWRITE YOUR MSG\n"); <br/> fgets(str,SIZE,stdin); <br/> strncpy(buff,str,SIZE); <br/> sleep(1); <br/> *buff='\0'; <br/> *str='\0'; <br/> printf("\n SERVER IS WAITING FOR REPLY........\n"); <br/> while(1) <br/> { <br/> if(*str!='\0') <br/> { <br/> printf("\nCLIENT JUST GAVE REPLY\n"); <br/> fputs(str,stdout); <br/> break; <br/> } <br/> strncpy(str,buff,SIZE); <br/> } <br/> return(0); <br/> } |
Source projectgeek.com