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]);
    }

Implement Best-Fit memory management schemes.

#include<iostream>
using namespace std;

typedef struct Process
{
    int process_id;
    int processSize;
    int allocatedHole;
}Process;

typedef struct Hole
{
    int hole_id;
    int holeSize;
    bool allocated;
}Hole;

Implement First-Fit memory management schemes.

#include<iostream>
using namespace std;

typedef struct Process
{
    int process_id;
    int processSize;
    int allocatedHole;
}Process;

typedef struct Hole
{
    int hole_id;
    int holeSize;
    bool allocated;
}Hole;

int main()
{
    int n,m,i,j,flag=0;
    cout<<"Enter the number of holes : ";
    cin>>m;
    Hole hole[m+1];
    for(i=1;i<=m;i++)

Implement the Priority scheduling for, Given the list of processes, their CPU burst times and arrival times, print the Gantt chart for Priority and also compute and print the average waiting time and average turnaround time.

#include<stdio.h>

main()

{

float avgwt,avgtt;

char pname[10][10],c[10][10];

int wt[10],tt[10],bt[10],pt[10],t,q,i,n,sum=0,sbt=0,ttime,j,ss=10; printf("\n\n Enter the number of processes : "); scanf("%d",&n);

printf("\n\n Enter the NAME and BURSTTIME "); for(i=0;i<n;i++)

{

printf("\n\n NAME : "); scanf("%s",&pname[i]); printf("\n\n BURSTTIME : "); scanf("%d",&bt[i]);

}


printf("\n\n Enter the priorities of the processes "); for(i=0;i<n;i++)

{

printf("\n\n Priority of process%d : ",i+1); scanf("%d",&pt[i]);

}

for(i=0;i<n;i++)

for(j=i+1;j<n;j++)

Implement the Round Robin scheduling for, Given the list of processes, their CPU burst times and arrival times, print the Gantt chart for RR and also compute and print the average waiting time and average turnaround time.

#include<stdio.h>

main()

{

int pt[10][10],a[10][10],at[10],pname[10][10],i,j,n,k=0,q,sum=0;

float avg;

printf("\n\n Enter the number of processes : "); scanf("%d",&n);

for(i=0;i<10;i++)

{

for(j=0;j<10;j++)

Implement the SJF(Shortest job first) scheduling for, Given the list of processes, their CPU burst times and arrival times, print the Gantt chart for SJF and also compute and print the average waiting time and average turnaround time.

#include<stdio.h>

main()

{

float avgwt,avgtt;

char pname[10][10],c[10][10];

int wt[10],tt[10],bt[10],at[10],t,q,i,n,sum=0,sbt=0,ttime,j,ss=0; printf("\n\n Enter the number of processes: "); scanf("%d",&n);

printf("\n\n Enter the NAME, BURSTTIME, and ARRIVALTIME of the processes ");

for(i=0;i<n;i++)

{

printf("\n\n NAME : "); scanf("%s",&pname[i]); printf("\n\n BURST TIME : ");

scanf("%d",&bt[i]);

printf("\n\n ARRIVAL TIME : "); scanf("%d",&at[i]);

Implement the FCFS(First come first serve) for, Given the list of processes, their CPU burst times and arrival times, print the Gantt chart for FCFS and also compute and print the average waiting time and average turnaround time.

#include<string.h>
#include<stdio.h>
#include<string.h>

 void main()

{

float avgwt,avgtt;
char pname[10][10],c[10][10];
int wt[10],tt[10],bt[10],at[10],t,q,i,n,sum=0,sbt=0,ttime,j,ss=0;

printf("\n\n Enter the number of processes: ");
scanf("%d",&n);

printf("\n\n Enter the NAME , BURST TIME and ARRIVAL TIME of the process");

for(i=0;i<n;i++)

     {

         printf("\n\n NAME : "); scanf("%s",&pname[i]);
printf("\n BURST TIME : "); scanf("%d",&bt[i]);

Write a program for following system calls of UNIX operating system: fork, exec, getpid, exit, wait, close, stat, opendir, readdir .

#include<stdio.h>
main(int arc,char*ar[])

{

int pid;
char s[100];
pid=fork();

if(pid<0)
printf("error");

else if(pid>0)
{
  wait(NULL);
  printf("\n Parent Process:\n");
  printf("\n\tParent Process id:%d\t\n",getpid());
  execlp("cat","cat",ar[1],(char*)0); error("can’t execute cat %s,",ar[1]);