Posts

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...

JAVA PROGRAM TO UNDERSTAND FINAL METHOD

 class XYZ{      final void demo(){       System.out.println("XYZ Class Method");    }   }         class ABC extends XYZ{      void demo(){       System.out.println("ABC Class Method");    }            public static void main(String args[]){         ABC obj= new ABC();         obj.demo();      }   }

JAVA PROGRAM TO PERFORM MULTI THREADING USING RUNNABLE INTERFACE

 class Multithreading implements Runnable {     public void run()     {         try {             // Displaying the thread that is running             System.out.println(                 "Thread " + Thread.currentThread().getId()                 + " is running");         }         catch (Exception e) {                          // Throwing an exception             System.out.println("Exception is caught");         }     } } // Main Class public class Geeks {     public static void main(String[] args)     {         int n = 8; // Number of threads         for (int i = 0; i < n; i++) {...

JAVA RECORD PROGRAM TO UNDERSTAND MULTIPLE INHERITANCE

 // Define two interfaces interface Interface1 {     void method1(); } interface Interface2 {     void method2(); } // Implement both interfaces in a single class class MyClass implements Interface1, Interface2 {     @Override     public void method1() {         System.out.println("Implementation of method1");     }     @Override     public void method2() {         System.out.println("Implementation of method2");     } } public class Main {     public static void main(String[] args) {         // Create an instance of MyClass         MyClass myClass = new MyClass();         // Call methods from both interfaces         myClass.method1();         myClass.method2();     } }

JAVA RECORD PROGRAM TO UNDERSTAND EXCEPTION HANDLING

import java.util.Scanner; public class JavaExample {   public static void main(String[] args) {     int num1, num2;     Scanner scan = new Scanner(System.in);     System.out.print("Enter first number(dividend): ");     num1 = scan.nextInt();     System.out.print("Enter second number(divisor): ");     num2 = scan.nextInt();     try {       int div = num1 / num2;       System.out.println("Quotient: "+div);     }catch(ArithmeticException e){       System.out.println("Do not enter divisor as zero.");       System.out.println("Error Message: "+e);     }   } } 

JAVA RECORD PROGRAM TO UNDERSTAND STRING OPERATIONS

 public class StringExample {     public static void main(String[] args) {         // Creating a string         String str = "Hello, World!";                  // Length of the string         int length = str.length();         System.out.println("Length of the string: " + length);                  // Getting character at a specific index         char ch = str.charAt(7);         System.out.println("Character at index 7: " + ch);                  // Substring         String substr = str.substring(7, 12);         System.out.println("Substring from index 7 to 11: " + substr);                  // Converting to uppercase       ...

JAVA PROGRAM TO UNDERSTAND ABSTRACT METHODS AND CLASSES

 abstract class Animal {   abstract void makeSound();   public void eat() {     System.out.println("I can eat.");   } } class Dog extends Animal {   // provide implementation of abstract method   public void makeSound() {     System.out.println("Bark bark");   } } public class Main {   public static void main(String[] args) {     // create an object of Dog class     Dog d1 = new Dog();     d1.makeSound();     d1.eat();   } }

JAVA RECORD PROGRAM TO UNDERSTAND BANK OPERATIONS USING INHERITANCE

//Run this code in https://www.jdoodle.com/online-java-compiler  import java.util.Scanner; class Bank{     protected String name;     protected int accno;     protected double p;     public Bank(String n, int a, double p){         name = n;         accno = a;         this.p = p;     }     public void display(){         System.out.println("Customer Name: " + name);         System.out.println("Account Number: " + accno);         System.out.println("Principal Amount: " + p);     } } class Account extends Bank{     double amt;     public Account(String n, int acc, double p){         super(n, acc, p);         amt = 0.0;     }     public void deposit(){         Scanner in = new Scanner(System.in); ...