Sunday 30 August 2015

Implement the Producer – Consumer problem using semaphores (using UNIX system calls).

#include<stdio.h>
#include<stdlib.h>

int full=0,empty=3,x=0;

main()

{

int n;

void producer();
void consumer();
int wait(int);

Implement an Inter Process communication (using shared memory, pipes or message queues).

#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>

//#include<sys/ipc.h>
//#include<sys/uio.h>

#include<sys/types.h>
main()

{

int pid,pfd[2],n,a,b,c;

if(pipe(pfd)==-1)

{

printf("\nError in pipe connection\n"); exit(1);

}

Implement Contiguous memory file allocation technique.

#include<stdio.h>

main()
{

int nf, fc[20], mb[100], i, j, k, fb[100], fs[20], mc=0;

printf("\nEnter the number of files: "); scanf("%d",&nf);
for(i=0;i<nf;i++)

{

printf("\nEnter the capacity of file %d: ",i+1); scanf("%d",&fc[i]);

printf("\nEnter the starting address of file %d: ",i+1); scanf("%d",&fs[i]);

}

printf("\n---CONTIGUOUS FILE ALLOCATION---\n"); for(i=0;i<100;i++)
fb[i]=1;

Implement Worst-Fit memory management schemes.

#include<stdio.h>
#include<conio.h>


int main()
{
 int *Frag,*Files,*Block,nFile,nFrag,nBlock,i,j;
 int *FFile,*FBlock;
 int tmp,greatest;
 //Take Input of Block Size Information
 printf("\nEnter the Number of Blocks:");
 scanf("%d",&nBlock);
 Block=(int*)malloc(sizeof(int)*nBlock);
    FBlock=(int*)malloc(sizeof(int)*nBlock);
 for(i=1;i<=nBlock;i++)
 {
   printf("Block-%d Size :",i);
   scanf("%d",&Block[i]);
    }