23SE02IE043-Final OS
23SE02IE043-Final OS
Practical -1
Desai Krunal 23SE02IE043
Computer Organization SEIT2230
Practical -1
2. Factorial of a number
Input:-
Output:-
Desai Krunal 23SE02IE043
Computer Organization SEIT2230
Practical -1
Output:-
Operating System 23SE02IE043 SEIT2230
Krunal Desai
Practical 1
Basic linux commands
10. pwd : this command is use for a you are where working.
Operating System 23SE02IE043 SEIT2230
Krunal Desai
Practical:-2
Krunal Desai 23SE02IE043
Opreting system SEIT2230
Practical-3
1.Addition of two numbers:
echo "Enter the first number : "
read num1 echo "Enter the
second number : " read num2
sum=$((num1 + num2)) echo
"sum of two value is $sum"
Practical-3
Practical-3
Practical-3
Practical-3
echo "Result: $(($1 + $2))"
}
divide() { if [ $2 -
eq 0 ]; then
echo "Error: Division by zero is not allowed!"
else
echo "Result: $(($1 / $2))"
fi
}
Practical-3
case $choice in
1) add $num1 $num2 ;;
2) subtract $num1 $num2 ;;
3) multiply $num1 $num2 ;;
4) divide $num1 $num2 ;;
5) echo "Exiting..."; exit 0 ;;
*) echo "Invalid choice, please select between 1 to 5." ;; esac
Desai Krunal 23SE02IE043
Operating System SEIT2230
Practical - 5
#!/bin/bash
Practical - 5
#!/bin/bash
Practical 4.1
Output :
23SE02IE043 SEIT2230 OPERATING SYSTEM
Output:-
23SE02IE043 Desai Krunal
Practical 5.1
Terminologies
Memory Block: A fixed-size contiguous region of memory available for allocation.
Process Size: The amount of memory required by a process.
Allocation: Assigning a memory block to a process.
Fragmentation: Wasted memory due to inefficient allocation.
Deallocation: Releasing memory when a process completes execution.
Splitting: If a memory block is larger than required, it is split into allocated and free
sections.
Compaction: Merging scattered free memory to form larger blocks.
Advantages
Disadvantages
High memory wastage if a large block is allocated to a small process.
Higher processing time due to searching for the largest block.
Leads to inefficient space utilization over time.
23SE02IE043 Desai Krunal
Practical 5.1
Implementation Steps
Step 1: Input the Number of Memory Blocks and Their Sizes
Take input for total available memory.
Store memory block sizes in an array.
Step 2: Input the Number of Processes and Their Memory Requirements
Take input for the number of processes.
Store process memory requirements in an array.
Step 3: Worst Fit Allocation Logic
Sort free blocks in descending order.
For each process:
o Find the largest available block that can accommodate it.
o If found:
Allocate memory.
If extra space remains, split the block.
o If not found:
Mark process as unallocated.
Step 4: Deallocate Memory and Handle Fragmentation
When a process finishes, mark its memory as free.
Merge adjacent free blocks if needed.
Step 5: Display Results
Print a table showing:
o Process ID
o Required Memory
o Allocated Block Size
Show the updated memory block status.
Step 6: Calculate and Display Statistics
Total memory used.
Total memory wasted (fragmentation).
Number of unallocated processes.
23SE02IE043 Desai Krunal
Practical 5.1
Sample Input
1 100 Free
2 500 Free
3 200 Free
4 300 Free
5 600 Free
Process Allocation:
Process 1 (212 KB) -> Block 5 (600 KB) [388 KB Left]
Process 2 (417 KB) -> Block 2 (500 KB) [83 KB Left]
Process 3 (112 KB) -> Block 5 (388 KB) [276 KB Left]
Process 4 (426 KB) -> Not Allocated
Practical 6
#CODE
#include<stdio.h>
int main() {
do {
int processExecuted = 0;
if (!done[i]) {
int canExecute = 1;
if (canExecute) {
safe[count++] = i;
done[i] = 1;
processExecuted = 1;
if (!processExecuted) {
break;
if (count == p) {
printf("\nSafe sequence:\n");
printf("\n");
return 0;
}
23SE02IE043 SEIT2230 OPERATING SYSTEM
OUTPUT:-
Desai Krunal 23SE02IE043
Operating System SEIT2230
Practical – 7.1
Practical – 7.1
Desai Krunal 23SE02IE043
Operating System SEIT2230
Practical-7.2
Practical-7.2
}
if(flag1 == 0){ for(j = 0; j <
no_of_frames; ++j){ if(frames[j]
== -1){ counter++; faults++;
frames[j] = pages[i]; time[j] =
counter; flag2 = 1; break;
}
}
}
if(flag2 == 0){ pos = findLRU(time,
no_of_frames); counter++;
faults++; frames[pos] = pages[i];
time[pos] = counter;
} printf("\n"); for(j = 0; j <
no_of_frames; ++j){
printf("%d\t", frames[j]);
}
}
printf("\n\nTotal Page Faults = %d", faults); return
0;
}
Desai Krunal 23SE02IE043
Operating System SEIT2230
Practical-7.2