InterProcess Communications using Shared Memory
Study the following system calls.
Shared memory shmget, shmat, shmdt, shmctl
Additional system calls (For your understanding)
Pipe pipe, mkfifo, mknod, open, read, write, close
Message Queue msgget, msgsnd, msgrcv, msgctl
Aim:
Develop the following applications that uses interprocess communication concepts using shared memory.
1.Develop an application for getting a name in parent and convert it into uppercase in child using shared memory.
2.Develop an client / server application for file transfer using shared memory.
- Develop an client/server chat application using shared memory.
Comment:
This program should be run as a single program in which parent is one process and child is another process.
Client / server:
Keep common code and parent code in one program as server.c
Keep common code and child code in another program as client.c
Run server.c in one terminal and client.c in another terminal. Communicate between the two processes.
Example :
Shared memory :
#include <sys/ipc.h>
# define NULL 0
#include <sys/shm.h>
#include <sys/types.h>
# include<unistd.h>
# include<stdio.h>
# include<stdlib.h>
# include<string.h>
#include <sys/wait.h>
#include <stdio_ext.h>
// parent writing a char in shared memory and child reads it and prints it. int main()
{ int pid; char *a,*b,c; int id,n,i;
// you can create a shared memory between parent and child here or you can //create inside them separately.
id=shmget(111,50,IPC_CREAT | 00666);
pid=fork(); if(pid>0) //parent
{
// id=shmget(111,50,IPC_CREAT | 00666); a=shmat(id,NULL,0);
a[0]=d;
wait(NULL); shmdt(a);
} else //child
{ sleep(3);
//id=shmget(111,50,0); b=shmat(id,NULL,0); printf(
child %c
,b[0]);
shmdt(b); } shmctl(id, IPC_RMID,NULL);
}

![[Solved] UCS1411 Exercise 5-InterProcess Communications on Shared Memory](https://assignmentchef.com/wp-content/uploads/2022/08/downloadzip.jpg)

![[Solved] UCS1411 Exercise 8- Memory Management Algorithms](https://assignmentchef.com/wp-content/uploads/2022/08/downloadzip-1200x1200.jpg)
Reviews
There are no reviews yet.