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
#include
#include
#include
#include
#define SIZE 124
int main()
{
char *buff,*str;
buff=(char*)malloc(124);
str=(char*)malloc(124);
*str='\0';
int shmid,i=0;
if((shmid=shmget(9999,SIZE,IPC_CREAT|0666))<0)
printf("\nERROR IN SHMID\n");
if((buff=shmat(shmid,NULL,0))<0)
printf("ERROR IN SHM ATTACH\n");
while(1)
{
if(*str!='\0')
{
printf("\nTHE SERVER JUST SEND THIS MESSAGE\n\n");
fputs(str,stdout);
break;
}
strncpy(str,buff,SIZE);
}
*str='\0';
*buff='\0';
printf("\nREPLY \n\n");
fgets(str,SIZE,stdin);
strncpy(buff,str,SIZE);
sleep(1);
*buff='\0';
return(0);
}
Server
#include
#include
#include
#include
#define SIZE 124
int main()
{
char *buff,*str;
buff=(char*)malloc(124);
str=(char*)malloc(124);
int shmid;
if((shmid=shmget(9999,SIZE,IPC_CREAT|0666))<0)
printf("\nERROR IN SHMID\n");
if((buff=shmat(shmid,NULL,0))<0)
printf("ERROR IN SHM ATTACH\n");
printf("\nWRITE YOUR MSG\n");
fgets(str,SIZE,stdin);
strncpy(buff,str,SIZE);
sleep(1);
*buff='\0';
*str='\0';
printf("\n SERVER IS WAITING FOR REPLY........\n");
while(1)
{
if(*str!='\0')
{
printf("\nCLIENT JUST GAVE REPLY\n");
fputs(str,stdout);
break;
}
strncpy(str,buff,SIZE);
}
return(0);
}


Leave a Reply