Last Programs Os New File Eeeee
Last Programs Os New File Eeeee
Last Programs Os New File Eeeee
EXPERIMENT-5
OBJECTIVE:
Write a C program to illustrate the Pipes IPC mechanism
a) pipes
program
#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>
#define MSGSIZE 16
int main()
char inbuf[MSGSIZE];
int p[2], i;
if (pipe(p) < 0)
exit(1);
return 0;
OUTPUT:
[227Y1A0544@localhost ~]$ vi pipes.c
hello, world #1
hello, world #2
hello, world #3
AIM: Write a C program to illustrate the following IPC mechanisms
b) FIFO
OBJECTIVE:
Write a C program to illustrate the FIFO IPC mechanism
PROGRAM:
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
int main()
{
int fd;
nt main()
{
int fd;
char *myfifo ="myfile.txt";
mkfifo(myfifo, 0666);
char arr1[80], arr2[80];
while (1)
{
fd = open(myfifo, O_WRONLY);
scanf("%s",arr2, 80, stdin);
write(fd, arr2, strlen(arr2)+1);
close(fd);
fd = open(myfifo, O_RDONLY);
read(fd, arr1, sizeof(arr1));
printf("User2: %s\n&", arr1);
close(fd);
}
return 0;
}
OUTPUT:
[227Y1A0544@localhost ~]$ cat>myfile.txt
^Z
[6]+ Stopped cat > myfile.txt
[227Y1A0544@localhost ~]$ vi f1.c
[227Y1A0544@localhost ~]$ cc f1.c
[227Y1A0544@localhost ~]$ ./a.out
hii
User2: hii
AIM: Write a C program to illustrate the following IPC mechanisms
c) MESSAGE QUEUES
OBJECTIVE:
Write a C program to illustrate the MESSAGE QUEUES IPC mechanism
#include <stdio.h>
#include <sys/ipc.h>
#include <sys/msg.h>
struct mesg_buffer
long mesg_type;
char mesg_text[100];
}message;
int main()
key_t key;
int msgid;
key=ftok("progfile",65);
msgid=msgget(key,0666|IPC_CREAT);
message.mesg_type=1;
printf("Write Data:");
scanf("%s",message.mesg_text);
return 0;
OUTPUT:
#include <stdio.h>
#include <sys/ipc.h>
#include <sys/msg.h>
struct mesg_buffer
long mesg_type;
char mesg_text[100];
}message;
int main()
key_t key;
int msgid;
key = ftok("progfile",65);
msgid = msgget(key,0666|IPC_CREAT);
msgrcv(msgid,&message,sizeof(message),1,0);
msgctl(msgid,IPC_RMID,NULL);
return 0;
OUTPUT:
OBJECTIVE:
Write a C program to illustrate the shared memory IPC mechanism
#include <sys/shm.h>
#include <stdio.h>
int main()
key_t key=ftok("shmfile",65);
int shmid=shmget(key,1024,0666|IPC_CREAT);
printf("Write Data:");
scanf("%s",str);
shmdt(str);
return 0;
output:
Write Data:welcome
#include <sys/shm.h>
#include <stdio.h>
int main()
key_t key=ftok("shmfile",65);
int shmid=shmget(key,1024,0666|IPC_CREAT);
char *str=(char*)shmat(shmid,(void*)0,0);
shmdt(str);
shmctl(shmid,IPC_RMID,NULL);
return 0;
Viva questions
1. What is FIFO?
a) Paging
#include<stdio.h>
main()
scanf("%d",&ms);
scanf("%d",&ps);
nop = ms/ps;
scanf("%d",&np);
rempages = nop;
for(i=1;i<=np;i++)
scanf("%d",&s[i]);
if(s[i] >rempages)
printf("\nMemory is Full");
break;
}
for(j=0;j<s[i];j++)
scanf("%d",&fno[i][j]);
else
pa=fno[x][y]*ps+offset;
Memory is Full
#include<stdio.h>
#include<stdlib.h>
struct list
{
int seg;
int base;
int limit;
struct list *next;
} *p;
void insert(struct list *q,int base,int limit,int seg)
{
if(p==NULL)
{
p=malloc(sizeof(struct list));
p->limit=limit;
p->base=base;
p->seg=seg;
p->next=NULL;
}
else
{
while(q->next!=NULL)
{
q=q->next;
printf("yes");
}
q->next=malloc(sizeof(struct list));
q->next ->limit=limit;
q->next ->base=base;
q->next ->seg=seg;
q->next ->next=NULL;
}
}
int find(struct list *q,int seg)
{
while(q->seg!=seg)
{
q=q->next;
}
return q->limit;
}
int search(struct list *q,int seg)
{
while(q->seg!=seg)
{
q=q->next;
}
return q->base;
}
main()
{
p=NULL;
int seg,offset,limit,base,c,s,physical;
printf("enter segment table\n");
printf("enter -1 as segment value for termination\n");
do
{
printf("enter seg number:");
scanf("%d",&seg);
if(seg!=-1)
{
printf(" enter base value");
scanf("%d",&base);
printf("enter value for limit");
scanf("%d",&limit);
insert(p,base,limit,seg);
}
}
while(seg!=-1);
printf("enter offset");
scanf("%d",&offset);
printf("enter b segmentation number");
scanf("%d",&seg);
c=find(p,seg);
s=search(p,seg);
if(offset<c)
{
physical=s+offset;
printf("address in physical memory%d\n",physical);
}
else
{
printf("error");
}
output:
[227Y1A0541@localhost ~]$ vi segnew.c
[227Y1A0541@localhost ~]$ cc segnew.c
[227Y1A0541@localhost ~]$ ./a.out
enter segment table
enter -1 as segment value for termination
enter seg number:1
enter base value2000
enter value for limit100
enter seg number:2
enter base value2500
enter value for limit100
enter seg number:-1
enter offset90
enter b segmentation number2
address in physical memory2590
(or)
#include <stdio.h>
int main()
int a[100][100],b[1000],i,j,n,x,base,size,seg,off;
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&size);
a[i][0]=size;
scanf("%d",&base);
a[i][i]=base;
for(j=0;j<size;j++)
x=0;
scanf("%d",&x);
b[base]=x;
base++;
b[base]=x;
scanf("%d %d",&seg,&off);
if(off<a[seg][0])
{
int abs=a[seg][1]+off;
printf("\n %d+%d=%d\n",a[seg][1],off,abs);
else
printf("Error in Locating");
Output:
12345
10 7 8 9
12
10+2=12
The Element 9 Is At 12
Experiment-6
Viva questions
1. What is memory management?
3. Define thrashing.
5. Define Swapping.
8. Define Segmentation.
9. Define Fragmentation.