Posts

Showing posts with the label BSC OS LAB

PROGRAM TO UNDERSTAND PRODUCER CONSUMER PROBLEM

 #include <stdio.h> #include <stdlib.h> // Initializing the mutex variable with the value 1. int mutex = 1; // Initializing the full variable with the value 0. int full = 0; // empty variable will store the number of empty slots in the buffer. int empty = 10, data = 0; // A function that will resemble producers' production of data void producer() {     // decrementing the value of mutex     --mutex;     // Increase the number of full slots     ++full;     // decrementing the number of slots available     --empty;     // incrementing data which means that the data is produced.     data++;     printf("\nProducer produces item number: %d\n", data);     // incrementing the value of mutex     ++mutex; } // A function that will resemble the consumer's consumption of data void consumer() {     // decrementing the value of mutex     --mutex;   ...

PROGRAM FOR BANKERS ALGORITHM FOR DEADLOCK AVOIDENCE

#include<stdio.h> int main() {   /* array will store at most 5 process with 3 resoures if your process or    resources is greater than 5 and 3 then increase the size of array */   int p, c, count = 0, i, j, alc[5][3], max[5][3], need[5][3], safe[5], available[3], done[5], terminate = 0;   printf("Enter the number of process and resources");   scanf("%d %d", & p, & c);   // p is process and c is diffrent resources    printf("enter allocation of resource of all process %dx%d matrix", p, c);   for (i = 0; i < p; i++) {     for (j = 0; j < c; j++) {       scanf("%d", & alc[i][j]);     }   }   printf("enter the max resource process required %dx%d matrix", p, c);   for (i = 0; i < p; i++) {     for (j = 0; j < c; j++) {       scanf("%d", & max[i][j]);     }   }   printf("enter the  available resource");   f...

PROGRAM TO SIMULATE MVT AND MFT MEMORY MANAGEMENT TECHNIQUES

  #include<stdio.h> #include<conio.h> main() { int ms, bs, nob, ef,n, mp[10],tif=0; int i,p=0; clrscr(); printf("Enter the total memory available (in Bytes) -- "); scanf("%d",&ms); printf("Enter the block size (in Bytes) -- "); scanf("%d", &bs); nob=ms/bs; ef=ms - nob*bs; printf("\nEnter the number of processes -- "); scanf("%d",&n); for(i=0;i<n;i++) { printf("Enter memory required for process %d (in Bytes)-- ",i+1); scanf("%d",&mp[i]); } printf("\nNo. of Blocks available in memory -- %d",nob); printf("\n\nPROCESS\tMEMORY REQUIRED\t ALLOCATED\tINTERNAL FRAGMENTATION"); for(i=0;i<n && p<nob;i++) { printf("\n %d\t\t%d",i+1,mp[i]); if(mp[i] > bs) printf("\t\tNO\t\t---"); else { printf("\t\tYES\t%d",bs-mp[i]); tif = tif + bs-mp[i]; p++; } } if(i<n) printf("\nMemory is Full, Remaining Processes cannot be acc...

PROGRAM TO UNDERSTAND ROUND ROBIN SCHEDULING ALGORITHM

 /*  * Round Robin Scheduling Program in C  */   #include<stdio.h>   int main() {     //Input no of processed     int  n;     printf("Enter Total Number of Processes:");     scanf("%d", &n);     int wait_time = 0, ta_time = 0, arr_time[n], burst_time[n], temp_burst_time[n];     int x = n;       //Input details of processes     for(int i = 0; i < n; i++)     {         printf("Enter Details of Process %d \n", i + 1);         printf("Arrival Time:  ");         scanf("%d", &arr_time[i]);         printf("Burst Time:   ");         scanf("%d", &burst_time[i]);         temp_burst_time[i] = burst_time[i];     }       //Input time slot     int time_slot;     printf("Enter Time...

PROGRAM TO UNDERSTAND PRIORITY SCHEDULING ALGORITHM

 /*  * C program to implement priority scheduling  */   #include <stdio.h>   //Function to swap two variables void swap(int *a,int *b) {     int temp=*a;     *a=*b;     *b=temp; } int main() {     int n;     printf("Enter Number of Processes: ");     scanf("%d",&n);       // b is array for burst time, p for priority and index for process id     int b[n],p[n],index[n];     for(int i=0;i<n;i++)     {         printf("Enter Burst Time and Priority Value for Process %d: ",i+1);         scanf("%d %d",&b[i],&p[i]);         index[i]=i+1;     }     for(int i=0;i<n;i++)     {         int a=p[i],m=i;           //Finding out highest priority element and placing it at its desired position        ...

PROGRAM TO UNDERSTAND SJF SCHEDULING ALGORITHM

 /*  * C Program to Implement SJF Scheduling  */   #include<stdio.h> int main() {     int bt[20],p[20],wt[20],tat[20],i,j,n,total=0,totalT=0,pos,temp;     float avg_wt,avg_tat;     printf("Enter number of process:");     scanf("%d",&n);       printf("\nEnter Burst Time:\n");     for(i=0;i<n;i++)     {         printf("p%d:",i+1);         scanf("%d",&bt[i]);         p[i]=i+1;     }       //sorting of burst times     for(i=0;i<n;i++)     {         pos=i;         for(j=i+1;j<n;j++)         {             if(bt[j]<bt[pos])                 pos=j;         }           temp=bt[i];       ...

PROGRAM TO UNDERSTAND FCFS SCHEDULING ALGORITHM

 /*  * FCFS Scheduling Program in C  to calculate average waiting time and turn around time  */   #include <stdio.h> int main() {     int pid[15];     int bt[15];     int n;     printf("Enter the number of processes: ");     scanf("%d",&n);       printf("Enter process id of all the processes: ");     for(int i=0;i<n;i++)     {         scanf("%d",&pid[i]);     }       printf("Enter burst time of all the processes: ");     for(int i=0;i<n;i++)     {         scanf("%d",&bt[i]);     }       int i, wt[n];     wt[0]=0;       //for calculating waiting time of each process     for(i=1; i<n; i++)     {         wt[i]= bt[i-1]+ wt[i-1];     }       printf("Process ID...

BSC OS LAB PROGRAM TO UNDERSTAND BASIC LINUX COMMANDS

 pwd command The pwd command allows you to print the current working directory on your terminal. It’s a very basic command and solves its purpose very well. adc@2lab-PC-60:~$ pwd Output: /home/adc mkdir command The mkdir command allows you to create directories from within the terminal. adc@2lab-PC-60:~$ mkdir avrk adc@2lab-PC-60:~$ cd avrk adc@2lab-PC-60:~/avrk$  rmdir command Removes an empty directory. adc@2lab-PC-60:~$ rmdir avrk adc@2lab-PC-60:~$ grep command The grep command stands for “global regular expression print,” which reflects its ability to search for regular expressions across multiple lines and files. dc@2lab-PC-60:~$ grep "pwd" linux Output: pwd command The pwd command allows you to print the current working directory on your terminal. It’s a very basic command and solves its purpose very well. chmod and chown commands The chmod and chown commands are used to modify file permissions and ownership in Linux.The chmod command is used to change the permissions o...