0% found this document useful (0 votes)
8 views

333063_OSSP Assignment 5

The document describes an assignment on inter-process communication using shared memory with System V. It includes client and server programs where the server creates a shared memory segment to write a message, and the client reads and displays that message. The provided code demonstrates the implementation of these functionalities in C programming language.

Uploaded by

Kaustubh Joshi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

333063_OSSP Assignment 5

The document describes an assignment on inter-process communication using shared memory with System V. It includes client and server programs where the server creates a shared memory segment to write a message, and the client reads and displays that message. The provided code demonstrates the implementation of these functionalities in C programming language.

Uploaded by

Kaustubh Joshi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

ASSIGNMENT 5

Name : Shaunak Godbole

Roll no.: 333063

PRN.: 22010373

Batch: C3

Inter-process Communication using Shared Memory using System V. Application to


demonstrate: Client and Server Programs in which server process creates a shared memory
segment and writes the message to the shared memory segment. Client process reads the
message from the shared memory segment and displays it to the screen.

CODE :
PART 1 :

#include<stdio.h>

#include<stdlib.h>

#include<unistd.h>

#include<sys/shm.h>

#include<string.h>

int main()

int i;

void *shared_memory;

char buff[100];

int shmid;

shmid=shmget((key_t)2345, 1024, 0666|IPC_CREAT);


//creates shared memory segment with key 2345, having size 1024 bytes. IPC_CREAT is used to
create the shared segment if it does not exist. 0666 are the permissions on the shared segment

printf("Key of shared memory is %d\n",shmid);

shared_memory=shmat(shmid,NULL,0);

//process attached to shared memory segment

printf("Process attached at %p\n",shared_memory);

//this prints the address where the segment is attached with this process

printf("Enter some data to write to shared memory\n");

read(0,buff,100); //get some input from user

strcpy(shared_memory,buff); //data written to shared memory

printf("You wrote : %s\n",(char *)shared_memory);

Part 2 :

#include<stdio.h>

#include<stdlib.h>

#include<unistd.h>

#include<sys/shm.h>

#include<string.h>

int main()

int i;

void *shared_memory;
char buff[100];

int shmid;

shmid=shmget((key_t)2345, 1024, 0666);

printf("Key of shared memory is %d\n",shmid);

shared_memory=shmat(shmid,NULL,0); //process attached to shared memory segment

printf("Process attached at %p\n",shared_memory);

printf("Data read from shared memory is : %s\n",(char *)shared_memory);

OUTPUT :

You might also like