OS Lab Manual

Download as pdf or txt
Download as pdf or txt
You are on page 1of 38

3rd Sem, B.

E [CSE(AI&ML)] : Operating System IPCC [BCS303]

Experiment-1:Develop a c program to implement the Process system


calls f ork, exec, wait, create process, terminate process
1 //1. Develop a c program to implement the Process system calls (fork (), exec(), wait(), create
,→ process, terminate process)
2

3 #include <stdio.h>
4 #include <unistd.h>
5 #include <sys/wait.h>
6

7 int main() {
8 pid_t pid;
9

10 pid = fork();
11

12 if (pid == -1) {
13 // Error handling for fork failure
14 perror("fork");
15 return 1;
16 } else if (pid == 0) {
17 // Child process
18 printf("Child process\n");
19 // Use exec() to execute another program
20 execl("/bin/ls", "ls", "-l", NULL);
21 } else {
22 // Parent process
23 printf("Parent process\n");
24 // Wait for the child process to finish
25 wait(NULL);
26 printf("Child process finished\n");
27 }
28

29 return 0;
30 }

Dept. of CSE(AI&ML), GSSSIETW, Mysuru-570016 Page 1


3rd Sem, B.E [CSE(AI&ML)] : Operating System IPCC [BCS303]

Experiment-2:Simulate the following CPU scheduling algorithms to


find turnaround time and waiting time a FCFS b SJF c Round Robin d
Priority.
1 //2. Simulate the following CPU scheduling algorithms to find turnaround time and waiting time
,→ a) FCFS b) SJF c) Round Robin d) Priority
2 #include<stdio.h>
3

4 // Function to find the waiting time for all processes


5 void findWaitingTime(int processes[], int n, int bt[], int wt[]) {
6 wt[0] = 0;
7

8 for (int i = 1; i < n ; i++ )


9 wt[i] = bt[i-1] + wt[i-1];
10 }
11

12 // Function to find the turnaround time for all processes


13 void findTurnaroundTime(int processes[], int n, int bt[], int wt[], int tat[]) {
14 for (int i = 0; i < n; i++)
15 tat[i] = bt[i] + wt[i];
16 }
17

18 // Function to calculate average time


19 void findAverageTime(int processes[], int n, int bt[]) {
20 int wt[n], tat[n];
21

22 // Function to find waiting time of all processes


23 findWaitingTime(processes, n, bt, wt);
24

25 // Function to find turnaround time for all processes


26 findTurnaroundTime(processes, n, bt, wt, tat);
27

28 // Display processes along with their waiting time and turnaround time
29 printf("\nProcess Burst Time Waiting"
30 " Time Turn-Around Time\n");
31 int total_wt = 0, total_tat = 0;
32 for (int i = 0; i < n; i++) {
33 total_wt = total_wt + wt[i];
34 total_tat = total_tat + tat[i];
35 printf(" %d ", (i + 1));
36 printf(" %d ", bt[i]);
37 printf(" %d", wt[i]);
38 printf(" %d\n", tat[i]);
39 }

Dept. of CSE(AI&ML), GSSSIETW, Mysuru-570016 Page 2


3rd Sem, B.E [CSE(AI&ML)] : Operating System IPCC [BCS303]

40

41 printf("\nAverage waiting time = %.2f", (float)total_wt / (float)n);


42 printf("\nAverage turn-around time = %.2f", (float)total_tat / (float)n);
43 }
44

45 // Function to implement FCFS scheduling algorithm


46 void FCFS(int processes[], int n, int bt[]) {
47 findAverageTime(processes, n, bt);
48 }
49

50 // Function to implement SJF scheduling algorithm


51 void SJF(int processes[], int n, int bt[]) {
52 // Sort processes based on burst time
53 for (int i = 0; i < n-1; i++)
54 for (int j = 0; j < n-i-1; j++)
55 if (bt[j] > bt[j+1]) {
56 // Swap the processes
57 int temp = bt[j];
58 bt[j] = bt[j+1];
59 bt[j+1] = temp;
60

61 temp = processes[j];
62 processes[j] = processes[j+1];
63 processes[j+1] = temp;
64 }
65

66 findAverageTime(processes, n, bt);
67 }
68

69 // Function to implement Round Robin scheduling algorithm


70 void RoundRobin(int processes[], int n, int bt[], int quantum) {
71 int wt[n], tat[n];
72

73 // Initialize waiting time and turnaround time arrays


74 for (int i = 0; i < n; i++) {
75 wt[i] = 0;
76 tat[i] = 0;
77 }
78

79 int time = 0; // Current time


80

81 // Run until all processes are completed


82 while (1) {
83 int done = 1;

Dept. of CSE(AI&ML), GSSSIETW, Mysuru-570016 Page 3


3rd Sem, B.E [CSE(AI&ML)] : Operating System IPCC [BCS303]

84

85 // Traverse all processes


86 for (int i = 0; i < n; i++) {
87 // If burst time is greater than 0, process i is not done
88 if (bt[i] > 0) {
89 done = 0;
90

91 // If remaining burst time is less than or equal to quantum, finish the process
92 if (bt[i] <= quantum) {
93 time += bt[i];
94 wt[i] = time - bt[i];
95 bt[i] = 0;
96 } else {
97 // Reduce the burst time by the quantum time
98 time += quantum;
99 bt[i] -= quantum;
100 }
101 }
102 }
103

104 // If all processes are done, exit the loop


105 if (done == 1)
106 break;
107 }
108

109 // Calculate turnaround time


110 for (int i = 0; i < n; i++)
111 tat[i] = wt[i] + bt[i];
112

113 // Display processes along with their waiting time and turnaround time
114 printf("\nProcess Burst Time Waiting"
115 " Time Turn-Around Time\n");
116 int total_wt = 0, total_tat = 0;
117 for (int i = 0; i < n; i++) {
118 total_wt = total_wt + wt[i];
119 total_tat = total_tat + tat[i];
120 printf(" %d ", (i + 1));
121 printf(" %d ", bt[i]);
122 printf(" %d", wt[i]);
123 printf(" %d\n", tat[i]);
124 }
125

126 printf("\nAverage waiting time = %.2f", (float)total_wt / (float)n);


127 printf("\nAverage turn-around time = %.2f", (float)total_tat / (float)n);

Dept. of CSE(AI&ML), GSSSIETW, Mysuru-570016 Page 4


3rd Sem, B.E [CSE(AI&ML)] : Operating System IPCC [BCS303]

128 }
129

130 // Function to implement Priority scheduling algorithm


131 void Priority(int processes[], int n, int bt[], int priority[]) {
132

133 printf("Enter the priority for each process:\n");


134 for (int i = 0; i < n; i++) {
135 printf("Priority for Process %d: ", i + 1);
136 scanf("%d", &priority[i]);
137 }
138 // Sort processes based on priority
139 for (int i = 0; i < n-1; i++)
140 for (int j = 0; j < n-i-1; j++)
141 if (priority[j] > priority[j+1]) {
142 // Swap the processes
143 int temp = priority[j];
144 priority[j] = priority[j+1];
145 priority[j+1] = temp;
146

147 temp = bt[j];


148 bt[j] = bt[j+1];
149 bt[j+1] = temp;
150

151 temp = processes[j];


152 processes[j] = processes[j+1];
153 processes[j+1] = temp;
154 }
155

156 findAverageTime(processes, n, bt);


157 }
158

159 int main() {


160 int n; // Number of processes
161

162 printf("Enter the number of processes: ");


163 scanf("%d", &n);
164

165 int processes[n]; // Array to store process IDs


166 int bt[n]; // Array to store burst times
167 int priority[n]; // Array to store priority values
168

169 printf("Enter the burst times for each process:\n");


170 for (int i = 0; i < n; i++) {
171 processes[i] = i + 1;

Dept. of CSE(AI&ML), GSSSIETW, Mysuru-570016 Page 5


3rd Sem, B.E [CSE(AI&ML)] : Operating System IPCC [BCS303]

172 printf("Burst time for Process %d: ", i + 1);


173 scanf("%d", &bt[i]);
174 }
175

176

177

178 // FCFS Scheduling


179 // RoundRobin(processes, n, bt,3);
180 FCFS(processes, n, bt);
181 //SJF(processes, n, bt);
182

183 }
184 /* FCFS Scheduling - Expected Output for FCFS
185 Enter the number of processes: 3
186 Enter the burst times for each process:
187 Burst time for Process 1: 5
188 Burst time for Process 2: 1
189 Burst time for Process 3: 2
190

191 Process Burst Time Waiting Time Turn-Around Time


192 1 5 0 5
193 2 1 5 6
194 3 2 6 8
195

196 Average waiting time = 3.67


197 Average turn-around time = 6.33

Dept. of CSE(AI&ML), GSSSIETW, Mysuru-570016 Page 6


3rd Sem, B.E [CSE(AI&ML)] : Operating System IPCC [BCS303]

Experiment-3:Develop a C program to simulate producer-consumer


problem using semaphores
1 // Develop a C program to simulate producer-consumer problem using semaphores
2 #include <stdio.h>
3 #include <pthread.h>
4 #include <semaphore.h>
5 #include <unistd.h>
6

7 #define BUFFER_SIZE 5
8

9 int buffer[BUFFER_SIZE];
10 int in = 0, out = 0;
11

12 sem_t mutex, empty, full;


13

14 void *producer(void *arg) {


15 int item = 1;
16

17 while (1) {
18 sem_wait(&empty);
19 sem_wait(&mutex);
20

21 // Produce item
22 buffer[in] = item;
23 printf("Produced item %d\n", item);
24 in = (in + 1) % BUFFER_SIZE;
25 item++;
26

27 sem_post(&mutex);
28 sem_post(&full);
29

30 sleep(1); // Simulate production time


31 }
32

33 pthread_exit(NULL);
34 }
35

36 void *consumer(void *arg) {


37 int item;
38

39 while (1) {
40 sem_wait(&full);
41 sem_wait(&mutex);
42

Dept. of CSE(AI&ML), GSSSIETW, Mysuru-570016 Page 7


3rd Sem, B.E [CSE(AI&ML)] : Operating System IPCC [BCS303]

43 // Consume item
44 item = buffer[out];
45 printf("Consumed item %d\n", item);
46 out = (out + 1) % BUFFER_SIZE;
47

48 sem_post(&mutex);
49 sem_post(&empty);
50

51 sleep(2); // Simulate consumption time


52 }
53

54 pthread_exit(NULL);
55 }
56

57 int main() {
58 pthread_t producer_thread, consumer_thread;
59

60 // Initialize semaphores
61 sem_init(&mutex, 0, 1);
62 sem_init(&empty, 0, BUFFER_SIZE);
63 sem_init(&full, 0, 0);
64

65 // Create producer and consumer threads


66 pthread_create(&producer_thread, NULL, producer, NULL);
67 pthread_create(&consumer_thread, NULL, consumer, NULL);
68

69 // Join threads
70 pthread_join(producer_thread, NULL);
71 pthread_join(consumer_thread, NULL);
72

73 // Destroy semaphores
74 sem_destroy(&mutex);
75 sem_destroy(&empty);
76 sem_destroy(&full);
77

78 return 0;
79 }
80

81 In this program:
82

83 mutex semaphore is used to provide mutual exclusion while accessing the buffer.
84 empty semaphore is used to track the number of empty slots in the buffer.
85 full semaphore is used to track the number of filled slots in the buffer.
86 The producer waits on empty semaphore before producing an item and signals full

Dept. of CSE(AI&ML), GSSSIETW, Mysuru-570016 Page 8


3rd Sem, B.E [CSE(AI&ML)] : Operating System IPCC [BCS303]

,→ semaphore after producing an item.


87 The consumer waits on full semaphore before consuming an item and signals empty
,→ semaphore after consuming an item.
88 sleep() functions are used to simulate production and consumption time.

Dept. of CSE(AI&ML), GSSSIETW, Mysuru-570016 Page 9


3rd Sem, B.E [CSE(AI&ML)] : Operating System IPCC [BCS303]

Experiment-4:Develop a C program which demonstrates interprocess


communication between a reader process and a writer process. Use
mkfifo, open, read, write and close APIs in your program.
1 //Develop a C program which demonstrates interprocess communication between a reader process and
,→ a writer process. Use mkfifo, open, read, write and close APIs in your program
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <unistd.h>
5 #include <sys/types.h>
6 #include <sys/stat.h>
7 #include <fcntl.h>
8 #include <string.h>
9

10 #define FIFO_NAME "myfifo"


11 #define BUFFER_SIZE 256
12

13 int main() {
14 int fd;
15 char message[BUFFER_SIZE];
16

17 // Create the FIFO (named pipe)


18 mkfifo(FIFO_NAME, 0666);
19

20 // Writer process
21 if (fork() == 0) {
22 // Open the FIFO for writing
23 fd = open(FIFO_NAME, O_WRONLY);
24 if (fd == -1) {
25 perror("open");
26 exit(EXIT_FAILURE);
27 }
28

29 // Write messages to the FIFO


30 while (1) {
31 printf("Enter message to send: ");
32 fgets(message, BUFFER_SIZE, stdin);
33 write(fd, message, strlen(message) + 1);
34 }
35

36 // Close the FIFO


37 close(fd);
38 }
39 // Reader process

Dept. of CSE(AI&ML), GSSSIETW, Mysuru-570016 Page 10


3rd Sem, B.E [CSE(AI&ML)] : Operating System IPCC [BCS303]

40 else {
41 // Open the FIFO for reading
42 fd = open(FIFO_NAME, O_RDONLY);
43 if (fd == -1) {
44 perror("open");
45 exit(EXIT_FAILURE);
46 }
47

48 // Read messages from the FIFO


49 while (1) {
50 if (read(fd, message, BUFFER_SIZE) > 0) {
51 printf("Received message: %s", message);
52 }
53 }
54

55 // Close the FIFO


56 close(fd);
57 }
58

59 return 0;
60 }
61

62 In this program:
63

64 We create a named pipe (FIFO) using mkfifo.


65 The writer process opens the FIFO for writing (O_WRONLY), writes messages entered
,→ by the user to the FIFO using write, and then closes the FIFO.
66 The reader process opens the FIFO for reading (O_RDONLY), reads messages from the
,→ FIFO using read, and prints them to the console.
67 The communication between the writer and reader processes is achieved through the
,→ named pipe. Each process can read from or write to the pipe independently.
68 The program continues running indefinitely until manually terminated.
69 Compile and run the program, and you can enter messages in the writer process,
,→ which will be read and displayed by the reader process.

Dept. of CSE(AI&ML), GSSSIETW, Mysuru-570016 Page 11


3rd Sem, B.E [CSE(AI&ML)] : Operating System IPCC [BCS303]

Experiment-5:Develop a C program to simulate Bankers Algorithm for


DeadLock Avoidance.
1 //Develop a C program to simulate Bankers Algorithm for DeadLock Avoidance
2 #include <stdio.h>
3 #define MAX_PROCESSES 10
4 #define MAX_RESOURCES 10
5

6 int available[MAX_RESOURCES];
7 int maximum[MAX_PROCESSES][MAX_RESOURCES];
8 int allocation[MAX_PROCESSES][MAX_RESOURCES];
9 int need[MAX_PROCESSES][MAX_RESOURCES];
10 int work[MAX_RESOURCES];
11 int finish[MAX_PROCESSES];
12

13 int nProcesses, nResources;


14

15 // Function declarations
16 void initialize();
17 void input();
18 void display();
19 int isSafe();
20 void requestResource(int processNumber);
21 void releaseResource(int processNumber);
22

23 int main() {
24 initialize();
25 input();
26 display();
27

28 if (isSafe()) {
29 printf("\nSystem is in safe state.\n");
30

31 // Example: Request and release resources


32 int processNumber = 0;
33 requestResource(processNumber);
34 display();
35

36 releaseResource(processNumber);
37 display();
38 } else {
39 printf("\nSystem is in unsafe state.\n");
40 }
41

42 return 0;

Dept. of CSE(AI&ML), GSSSIETW, Mysuru-570016 Page 12


3rd Sem, B.E [CSE(AI&ML)] : Operating System IPCC [BCS303]

43 }
44

45 void initialize() {
46 printf("Enter the number of processes: ");
47 scanf("%d", &nProcesses);
48

49 printf("Enter the number of resources: ");


50 scanf("%d", &nResources);
51

52 printf("Enter the available resources:\n");


53 for (int j = 0; j < nResources; ++j) {
54 scanf("%d", &available[j]);
55 }
56

57 for (int i = 0; i < nProcesses; ++i) {


58 printf("Enter the maximum resources for process %d:\n", i);
59 for (int j = 0; j < nResources; ++j) {
60 scanf("%d", &maximum[i][j]);
61 }
62 }
63 }
64

65 void input() {
66 printf("Enter the allocation matrix:\n");
67 for (int i = 0; i < nProcesses; ++i) {
68 for (int j = 0; j < nResources; ++j) {
69 scanf("%d", &allocation[i][j]);
70 need[i][j] = maximum[i][j] - allocation[i][j];
71 }
72 finish[i] = 0;
73 }
74 }
75

76 void display() {
77 printf("\nAvailable Resources:\n");
78 for (int j = 0; j < nResources; ++j) {
79 printf("%d ", available[j]);
80 }
81

82 printf("\n\nMaximum Resources:\n");
83 for (int i = 0; i < nProcesses; ++i) {
84 for (int j = 0; j < nResources; ++j) {
85 printf("%d ", maximum[i][j]);
86 }

Dept. of CSE(AI&ML), GSSSIETW, Mysuru-570016 Page 13


3rd Sem, B.E [CSE(AI&ML)] : Operating System IPCC [BCS303]

87 printf("\n");
88 }
89

90 printf("\nAllocation Matrix:\n");
91 for (int i = 0; i < nProcesses; ++i) {
92 for (int j = 0; j < nResources; ++j) {
93 printf("%d ", allocation[i][j]);
94 }
95 printf("\n");
96 }
97 }
98

99 int isSafe() {
100 for (int j = 0; j < nResources; ++j) {
101 work[j] = available[j];
102 }
103

104 int count = 0;


105 while (count < nProcesses) {
106 int found = 0;
107 for (int i = 0; i < nProcesses; ++i) {
108 if (finish[i] == 0) {
109 int j;
110 for (j = 0; j < nResources; ++j) {
111 if (need[i][j] > work[j]) {
112 break;
113 }
114 }
115 if (j == nResources) {
116 for (int k = 0; k < nResources; ++k) {
117 work[k] += allocation[i][k];
118 }
119 finish[i] = 1;
120 found = 1;
121 ++count;
122 }
123 }
124 }
125 if (found == 0) {
126 break;
127 }
128 }
129

130 return (count == nProcesses);

Dept. of CSE(AI&ML), GSSSIETW, Mysuru-570016 Page 14


3rd Sem, B.E [CSE(AI&ML)] : Operating System IPCC [BCS303]

131 }
132

133 void requestResource(int processNumber) {


134 printf("\nEnter the resource request for process %d:\n", processNumber);
135 for (int j = 0; j < nResources; ++j) {
136 int request;
137 scanf("%d", &request);
138

139 if (request <= need[processNumber][j] && request <= available[j]) {


140 allocation[processNumber][j] += request;
141 need[processNumber][j] -= request;
142 available[j] -= request;
143 } else {
144 printf("\nInvalid request. Process must wait.\n");
145 break;
146 }
147 }
148 }
149

150 void releaseResource(int processNumber) {


151 printf("\nEnter the resource release for process %d:\n", processNumber);
152 for (int j = 0; j < nResources; ++j) {
153 int release;
154 scanf("%d", &release);
155

156 if (release <= allocation[processNumber][j]) {


157 allocation[processNumber][j] -= release;
158 need[processNumber][j] += release;
159 available[j] += release;
160 } else {
161 printf("\nInvalid release. Process must wait.\n");
162 break;
163 }
164 }
165 }
166

167 //Expected Output


168 Enter the number of processes: 5
169 Enter the number of resources: 4
170 Enter the available resources:
171 1
172 2
173 1
174 1

Dept. of CSE(AI&ML), GSSSIETW, Mysuru-570016 Page 15


3rd Sem, B.E [CSE(AI&ML)] : Operating System IPCC [BCS303]

175 Enter the maximum resources for process 0:


176 1
177 1
178 1
179 1
180 Enter the maximum resources for process 1:
181 2
182 2
183 2
184 2
185 Enter the maximum resources for process 2:
186 4
187 5
188 5
189 3
190 Enter the maximum resources for process 3:
191 4
192 1
193 1
194 1
195 Enter the maximum resources for process 4:
196 1
197 1
198 1
199 1
200 Enter the allocation matrix:
201 1
202 1
203 1
204 1
205 1
206 1
207 1
208 1
209 1
210 1
211 1
212 1
213 1
214 1
215 1
216 1
217 1
218 1

Dept. of CSE(AI&ML), GSSSIETW, Mysuru-570016 Page 16


3rd Sem, B.E [CSE(AI&ML)] : Operating System IPCC [BCS303]

219 1
220 1
221

222 Available Resources:


223 1 2 1 1
224

225 Maximum Resources:


226 1 1 1 1
227 2 2 2 2
228 4 5 5 3
229 4 1 1 1
230 1 1 1 1
231

232 Allocation Matrix:


233 1 1 1 1
234 1 1 1 1
235 1 1 1 1
236 1 1 1 1
237 1 1 1 1
238

239 System is in safe state.

Dept. of CSE(AI&ML), GSSSIETW, Mysuru-570016 Page 17


3rd Sem, B.E [CSE(AI&ML)] : Operating System IPCC [BCS303]

Experiment-6:Develop a C program to simulate the following


contiguous memory allocation Techniques: a Worst fit b Best fit c First
fit
1 //Develop a C program to simulate the following contiguous memory allocation Techniques: a)
,→ Worst fit b) Best fit c) First fit.
2

3 #include <stdio.h>
4 #define MAX_MEMORY_SIZE 1000
5 #define MAX_PROCESSES 10
6

7 typedef struct {
8 int pid; // Process ID
9 int size; // Process size
10 int allocated; // Allocation status (1 for allocated, 0 for unallocated)
11 } Process;
12

13 void worstFit(Process processes[], int numProcesses, int memory[], int


,→ numMemoryBlocks) {
14 for (int i = 0; i < numProcesses; i++) {
15 int worstFitIndex = -1;
16

17 for (int j = 0; j < numMemoryBlocks; j++) {


18 if (memory[j] >= processes[i].size) {
19 if (worstFitIndex == -1 || memory[j] > memory[worstFitIndex]) {
20 worstFitIndex = j;
21 }
22 }
23 }
24

25 if (worstFitIndex != -1) {
26 // Allocate memory to the process
27 processes[i].allocated = 1;
28 memory[worstFitIndex] -= processes[i].size;
29 printf("Process %d allocated to memory block %d using Worst Fit\n",
,→ processes[i].pid, worstFitIndex);
30 } else {
31 printf("Process %d cannot be allocated using Worst Fit\n",
,→ processes[i].pid);
32 }
33 }
34 }
35

36 void bestFit(Process processes[], int numProcesses, int memory[], int

Dept. of CSE(AI&ML), GSSSIETW, Mysuru-570016 Page 18


3rd Sem, B.E [CSE(AI&ML)] : Operating System IPCC [BCS303]

,→ numMemoryBlocks) {
37 for (int i = 0; i < numProcesses; i++) {
38 int bestFitIndex = -1;
39

40 for (int j = 0; j < numMemoryBlocks; j++) {


41 if (memory[j] >= processes[i].size) {
42 if (bestFitIndex == -1 || memory[j] < memory[bestFitIndex]) {
43 bestFitIndex = j;
44 }
45 }
46 }
47

48 if (bestFitIndex != -1) {
49 // Allocate memory to the process
50 processes[i].allocated = 1;
51 memory[bestFitIndex] -= processes[i].size;
52 printf("Process %d allocated to memory block %d using Best Fit\n",
,→ processes[i].pid, bestFitIndex);
53 } else {
54 printf("Process %d cannot be allocated using Best Fit\n",
,→ processes[i].pid);
55 }
56 }
57 }
58

59 void firstFit(Process processes[], int numProcesses, int memory[], int


,→ numMemoryBlocks) {
60 for (int i = 0; i < numProcesses; i++) {
61 for (int j = 0; j < numMemoryBlocks; j++) {
62 if (memory[j] >= processes[i].size) {
63 // Allocate memory to the process
64 processes[i].allocated = 1;
65 memory[j] -= processes[i].size;
66 printf("Process %d allocated to memory block %d using First Fit\n",
,→ processes[i].pid, j);
67 break;
68 }
69 }
70

71 if (!processes[i].allocated) {
72 printf("Process %d cannot be allocated using First Fit\n",
,→ processes[i].pid);
73 }
74 }

Dept. of CSE(AI&ML), GSSSIETW, Mysuru-570016 Page 19


3rd Sem, B.E [CSE(AI&ML)] : Operating System IPCC [BCS303]

75 }
76

77 int main() {
78 int memory[MAX_MEMORY_SIZE];
79 Process processes[MAX_PROCESSES];
80

81 int numProcesses, numMemoryBlocks;


82

83 printf("Enter the number of memory blocks: ");


84 scanf("%d", &numMemoryBlocks);
85

86 printf("Enter the sizes of memory blocks:\n");


87 for (int i = 0; i < numMemoryBlocks; i++) {
88 scanf("%d", &memory[i]);
89 }
90

91 printf("Enter the number of processes: ");


92 scanf("%d", &numProcesses);
93

94 printf("Enter the sizes of processes:\n");


95 for (int i = 0; i < numProcesses; i++) {
96 scanf("%d", &processes[i].size);
97 processes[i].pid = i;
98 processes[i].allocated = 0;
99 }
100

101 // Worst Fit


102 worstFit(processes, numProcesses, memory, numMemoryBlocks);
103

104 // Reset memory and processes allocation status


105 for (int i = 0; i < numMemoryBlocks; i++) {
106 memory[i] = MAX_MEMORY_SIZE;
107 }
108 for (int i = 0; i < numProcesses; i++) {
109 processes[i].allocated = 0;
110 }
111

112

113 // Best Fit


114 bestFit(processes, numProcesses, memory, numMemoryBlocks);
115

116 // Reset memory and processes allocation status


117 for (int i = 0; i < numMemoryBlocks; i++) {
118 memory[i] = MAX_MEMORY_SIZE;

Dept. of CSE(AI&ML), GSSSIETW, Mysuru-570016 Page 20


3rd Sem, B.E [CSE(AI&ML)] : Operating System IPCC [BCS303]

119 }
120 for (int i = 0; i < numProcesses; i++) {
121 processes[i].allocated = 0;
122 }
123

124 // First Fit


125 firstFit(processes, numProcesses, memory, numMemoryBlocks);
126

127 return 0;
128 }
129

130 //Expected Output


131 Enter the number of memory blocks: 3
132 Enter the sizes of memory blocks:
133 10
134 25
135 1
136 Enter the number of processes: 2
137 Enter the sizes of processes:
138 1
139 20
140 Process 0 allocated to memory block 2 using Best Fit
141 Process 1 allocated to memory block 1 using Best Fit

Dept. of CSE(AI&ML), GSSSIETW, Mysuru-570016 Page 21


3rd Sem, B.E [CSE(AI&ML)] : Operating System IPCC [BCS303]

Experiment-7:Develop a C program to simulate page replacement


algorithms: a FIFO b LRU
1 //Develop a C program to simulate page replacement algorithms: a) FIFO b) LRU
2 #include <stdio.h>
3 #include <stdbool.h>
4

5 #define MAX_PAGES 100


6 #define MAX_FRAMES 10
7

8 void fifo(int pages[], int n, int frames) {


9 int pageFaults = 0;
10 int frame[MAX_FRAMES];
11 bool isPresent[MAX_PAGES] = {false};
12 int rear = -1;
13

14 printf("Page\tFrame\n");
15

16 for (int i = 0; i < n; i++) {


17 printf("%d\t", pages[i]);
18

19 if (!isPresent[pages[i]]) {
20 pageFaults++;
21 if (rear < frames - 1) {
22 rear++;
23 } else {
24 rear = 0;
25 }
26 frame[rear] = pages[i];
27 isPresent[pages[i]] = true;
28 }
29

30 for (int j = 0; j < frames; j++) {


31 if (j <= rear) {
32 printf("%d ", frame[j]);
33 } else {
34 printf("- ");
35 }
36 }
37 printf("\n");
38 }
39 printf("Total Page Faults: %d\n", pageFaults);
40 }
41

42 void lru(int pages[], int n, int frames) {

Dept. of CSE(AI&ML), GSSSIETW, Mysuru-570016 Page 22


3rd Sem, B.E [CSE(AI&ML)] : Operating System IPCC [BCS303]

43 int pageFaults = 0;
44 int frame[MAX_FRAMES];
45 bool isPresent[MAX_PAGES] = {false};
46 int leastUsed[MAX_FRAMES] = {0};
47 int count = 0;
48

49 printf("Page\tFrame\n");
50

51 for (int i = 0; i < n; i++) {


52 printf("%d\t", pages[i]);
53

54 if (!isPresent[pages[i]]) {
55 pageFaults++;
56 if (count < frames) {
57 frame[count] = pages[i];
58 isPresent[pages[i]] = true;
59 leastUsed[count] = i;
60 count++;
61 } else {
62 int index = 0;
63 for (int j = 1; j < frames; j++) {
64 if (leastUsed[j] < leastUsed[index]) {
65 index = j;
66 }
67 }
68 isPresent[frame[index]] = false;
69 frame[index] = pages[i];
70 isPresent[pages[i]] = true;
71 leastUsed[index] = i;
72 }
73 } else {
74 for (int j = 0; j < frames; j++) {
75 if (frame[j] == pages[i]) {
76 leastUsed[j] = i;
77 break;
78 }
79 }
80 }
81

82 for (int j = 0; j < frames; j++) {


83 if (isPresent[pages[i]] && j < count) {
84 printf("%d ", frame[j]);
85 } else {
86 printf("- ");

Dept. of CSE(AI&ML), GSSSIETW, Mysuru-570016 Page 23


3rd Sem, B.E [CSE(AI&ML)] : Operating System IPCC [BCS303]

87 }
88 }
89 printf("\n");
90 }
91 printf("Total Page Faults: %d\n", pageFaults);
92 }
93

94 int main() {
95 int pages[MAX_PAGES];
96 int n, frames;
97 char choice;
98

99 printf("Enter the number of pages: ");


100 scanf("%d", &n);
101

102 printf("Enter the pages: ");


103 for (int i = 0; i < n; i++) {
104 scanf("%d", &pages[i]);
105 }
106

107 printf("Enter the number of frames: ");


108 scanf("%d", &frames);
109

110 printf("Choose a page replacement algorithm:\n");


111 printf("a) FIFO\n");
112 printf("b) LRU\n");
113 printf("Enter your choice: ");
114 scanf(" %c", &choice);
115

116 switch (choice) {


117 case ’a’:
118 fifo(pages, n, frames);
119 break;
120 case ’b’:
121 lru(pages, n, frames);
122 break;
123 default:
124 printf("Invalid choice\n");
125 }
126

127 return 0;
128 }
129

130 //Expected Output

Dept. of CSE(AI&ML), GSSSIETW, Mysuru-570016 Page 24


3rd Sem, B.E [CSE(AI&ML)] : Operating System IPCC [BCS303]

131 Enter the number of pages: 5


132 Enter the pages: 1
133 1
134 2
135 4
136 5
137 Enter the number of frames: 2
138 Choose a page replacement algorithm:
139 a) FIFO
140 b) LRU
141 Enter your choice: a
142 Page Frame
143 1 1 -
144 1 1 -
145 2 1 2
146 4 4 -
147 5 4 5
148 Total Page Faults: 4

Dept. of CSE(AI&ML), GSSSIETW, Mysuru-570016 Page 25


3rd Sem, B.E [CSE(AI&ML)] : Operating System IPCC [BCS303]

Experiment-8:Develop a C program to simulate SCAN disk scheduling


algorithm
1 //Develop a C program to simulate SCAN disk scheduling algorithm.
2 #include <stdio.h>
3 #include <stdlib.h>
4 void SCAN(int *requests, int n, int head, char direction) {
5 int total_movement = 0;
6 int i, j;
7 int min_index = 0;
8 int max_index = 0;
9

10 // Finding the min and max indexes in the request array


11 for (i = 0; i < n; i++) {
12 if (requests[i] < requests[min_index])
13 min_index = i;
14 if (requests[i] > requests[max_index])
15 max_index = i;
16 }
17

18 if (direction == ’l’) { // Left direction


19 // Move the head to the minimum index first
20 total_movement += abs(head - requests[min_index]);
21 printf("%d -> ", requests[min_index]);
22 head = requests[min_index];
23

24 // Move towards the beginning of the disk


25 for (i = min_index - 1; i >= 0; i--) {
26 total_movement += abs(head - requests[i]);
27 printf("%d -> ", requests[i]);
28 head = requests[i];
29 }
30

31 // Move towards the end of the disk


32 for (i = min_index + 1; i < n; i++) {
33 total_movement += abs(head - requests[i]);
34 printf("%d -> ", requests[i]);
35 head = requests[i];
36 }
37 } else if (direction == ’r’) { // Right direction
38 // Move the head to the maximum index first
39 total_movement += abs(head - requests[max_index]);
40 printf("%d -> ", requests[max_index]);
41 head = requests[max_index];
42

Dept. of CSE(AI&ML), GSSSIETW, Mysuru-570016 Page 26


3rd Sem, B.E [CSE(AI&ML)] : Operating System IPCC [BCS303]

43 // Move towards the end of the disk


44 for (i = max_index + 1; i < n; i++) {
45 total_movement += abs(head - requests[i]);
46 printf("%d -> ", requests[i]);
47 head = requests[i];
48 }
49

50 // Move towards the beginning of the disk


51 for (i = max_index - 1; i >= 0; i--) {
52 total_movement += abs(head - requests[i]);
53 printf("%d -> ", requests[i]);
54 head = requests[i];
55 }
56 }
57

58 printf("\nTotal head movement: %d\n", total_movement);


59 }
60

61 int main() {
62 int n, head, i;
63 char direction;
64 int *requests;
65

66 printf("Enter the number of requests: ");


67 scanf("%d", &n);
68

69 requests = (int*)malloc(n * sizeof(int));


70

71 printf("Enter the requests: ");


72 for (i = 0; i < n; i++) {
73 scanf("%d", &requests[i]);
74 }
75

76 printf("Enter the initial position of the head: ");


77 scanf("%d", &head);
78

79 printf("Enter the direction (l for left, r for right): ");


80 scanf(" %c", &direction);
81

82 printf("\nSCAN Schedule:\n");
83 SCAN(requests, n, head, direction);
84

85 free(requests);
86

Dept. of CSE(AI&ML), GSSSIETW, Mysuru-570016 Page 27


3rd Sem, B.E [CSE(AI&ML)] : Operating System IPCC [BCS303]

87 return 0;
88 }
89

90 //Expected Output
91 Enter the number of requests: 10
92 Enter the requests: 10
93 20
94 30
95 40
96 50
97 60
98 70
99 80
100 90
101 1
102 Enter the initial position of the head: 0
103 Enter the direction (l for left, r for right): l
104

105 SCAN Schedule:


106 1 -> 90 -> 80 -> 70 -> 60 -> 50 -> 40 -> 30 -> 20 -> 10 ->
107 Total head movement: 170

Dept. of CSE(AI&ML), GSSSIETW, Mysuru-570016 Page 28


3rd Sem, B.E [CSE(AI&ML)] : Operating System IPCC [BCS303]

Experiment-9:Simulate following File Organization Techniques a Single


level directory b Two level directory
1 #include <stdio.h>
2 #include <stdlib.h>
3

4 #define MAX_BLOCKS 100


5

6 // Structure to represent a block in the file system


7 typedef struct Block {
8 int blockNumber;
9 struct Block* next;
10 } Block;
11

12 // Structure to represent a file


13 typedef struct File {
14 int fileId;
15 Block* blocks;
16 struct File* next;
17 } File;
18

19 // Global variables
20 File* files[MAX_BLOCKS] = {NULL}; // Array to hold pointers to file blocks
21 int lastBlock = 0; // Variable to track the last allocated block
22

23 // Function to allocate a block for a file


24 Block* allocateBlock(int blockNumber) {
25 Block* newBlock = (Block*)malloc(sizeof(Block));
26 if (newBlock == NULL) {
27 printf("Memory allocation failed\n");
28 exit(1);
29 }
30 newBlock->blockNumber = blockNumber;
31 newBlock->next = NULL;
32 return newBlock;
33 }
34

35 // Function to create a new file


36 void createFile(int fileId) {
37 File* newFile = (File*)malloc(sizeof(File));
38 if (newFile == NULL) {
39 printf("Memory allocation failed\n");
40 exit(1);
41 }
42 newFile->fileId = fileId;

Dept. of CSE(AI&ML), GSSSIETW, Mysuru-570016 Page 29


3rd Sem, B.E [CSE(AI&ML)] : Operating System IPCC [BCS303]

43 newFile->blocks = NULL;
44 newFile->next = NULL;
45

46 // Insert the file into the files array


47 files[fileId] = newFile;
48 printf("File created with ID %d\n", fileId);
49 }
50

51 // Function to allocate blocks for a file


52 void allocateBlocks(int fileId, int numBlocks) {
53 File* file = files[fileId];
54 if (file == NULL) {
55 printf("File with ID %d does not exist\n", fileId);
56 return;
57 }
58

59 // Allocate blocks for the file


60 int i;
61 for (i = 0; i < numBlocks; i++) {
62 Block* newBlock = allocateBlock(++lastBlock);
63 newBlock->next = file->blocks;
64 file->blocks = newBlock;
65 }
66 printf("%d blocks allocated for file %d\n", numBlocks, fileId);
67 }
68

69 // Function to delete a file


70 void deleteFile(int fileId) {
71 File* file = files[fileId];
72 if (file == NULL) {
73 printf("File with ID %d does not exist\n", fileId);
74 return;
75 }
76

77 // Free blocks allocated to the file


78 Block* current = file->blocks;
79 while (current != NULL) {
80 Block* temp = current;
81 current = current->next;
82 free(temp);
83 }
84

85 // Free file structure


86 free(file);

Dept. of CSE(AI&ML), GSSSIETW, Mysuru-570016 Page 30


3rd Sem, B.E [CSE(AI&ML)] : Operating System IPCC [BCS303]

87 files[fileId] = NULL;
88 printf("File with ID %d deleted\n", fileId);
89 }
90

91 // Function to display allocated blocks for a file


92 void displayFile(int fileId) {
93 File* file = files[fileId];
94 if (file == NULL) {
95 printf("File with ID %d does not exist\n", fileId);
96 return;
97 }
98

99 printf("Blocks allocated for file %d: ", fileId);


100 Block* current = file->blocks;
101 while (current != NULL) {
102 printf("%d ", current->blockNumber);
103 current = current->next;
104 }
105 printf("\n");
106 }
107

108 int main() {


109 int choice, fileId, numBlocks;
110

111 while (1) {


112 printf("\nLinked File Allocation Strategies\n");
113 printf("1. Create File\n");
114 printf("2. Allocate Blocks\n");
115 printf("3. Delete File\n");
116 printf("4. Display File\n");
117 printf("5. Exit\n");
118 printf("Enter your choice: ");
119 scanf("%d", &choice);
120

121 switch (choice) {


122 case 1:
123 printf("Enter file ID: ");
124 scanf("%d", &fileId);
125 createFile(fileId);
126 break;
127 case 2:
128 printf("Enter file ID: ");
129 scanf("%d", &fileId);
130 printf("Enter number of blocks: ");

Dept. of CSE(AI&ML), GSSSIETW, Mysuru-570016 Page 31


3rd Sem, B.E [CSE(AI&ML)] : Operating System IPCC [BCS303]

131 scanf("%d", &numBlocks);


132 allocateBlocks(fileId, numBlocks);
133 break;
134 case 3:
135 printf("Enter file ID to delete: ");
136 scanf("%d", &fileId);
137 deleteFile(fileId);
138 break;
139 case 4:
140 printf("Enter file ID to display: ");
141 scanf("%d", &fileId);
142 displayFile(fileId);
143 break;
144 case 5:
145 exit(0);
146 default:
147 printf("Invalid choice\n");
148 }
149 }
150

151 return 0;
152 }
153

154 /*Expected Output


155 Linked File Allocation Strategies
156 1. Create File
157 2. Allocate Blocks
158 3. Delete File
159 4. Display File
160 5. Exit
161 Enter your choice: 2
162 Enter file ID: 1
163 Enter number of blocks: 10
164 10 blocks allocated for file 1
165

166 Linked File Allocation Strategies


167 1. Create File
168 2. Allocate Blocks
169 3. Delete File
170 4. Display File
171 5. Exit
172 Enter your choice: 4
173 Enter file ID to display: 1
174 Blocks allocated for file 1: 10 9 8 7 6 5 4 3 2 1

Dept. of CSE(AI&ML), GSSSIETW, Mysuru-570016 Page 32


3rd Sem, B.E [CSE(AI&ML)] : Operating System IPCC [BCS303]

175

176 Linked File Allocation Strategies


177 1. Create File
178 2. Allocate Blocks
179 3. Delete File
180 4. Display File
181 5. Exit
182 Enter your choice: 3
183 Enter file ID to delete: 1
184 File with ID 1 deleted

Experiment-10:Develop a C program to simulate the Linked file allocation


strategies.
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4

5 #define MAX_FILES 100


6 #define MAX_NAME_LENGTH 50
7

8 // Structure to represent a file


9 typedef struct File {
10 char name[MAX_NAME_LENGTH];
11 int size;
12 } File;
13

14 // Structure to represent a directory


15 typedef struct Directory {
16 char name[MAX_NAME_LENGTH];
17 int numFiles;
18 File files[MAX_FILES];
19 } Directory;
20

21 // Single level directory


22 Directory singleLevelDirectory;
23

24 // Two level directory


25 Directory twoLevelDirectory[MAX_FILES];
26

27 // Function to create a file in a single-level directory


28 void createFileSingleLevel(char* filename, int size) {
29 if (singleLevelDirectory.numFiles < MAX_FILES) {
30 strcpy(singleLevelDirectory.files[singleLevelDirectory.numFiles].name,
,→ filename);

Dept. of CSE(AI&ML), GSSSIETW, Mysuru-570016 Page 33


3rd Sem, B.E [CSE(AI&ML)] : Operating System IPCC [BCS303]

31 singleLevelDirectory.files[singleLevelDirectory.numFiles].size = size;
32 singleLevelDirectory.numFiles++;
33 printf("File ’%s’ created successfully in single-level directory\n",
,→ filename);
34 } else {
35 printf("Cannot create file. Single-level directory is full.\n");
36 }
37 }
38

39 // Function to delete a file from a single-level directory


40 void deleteFileSingleLevel(char* filename) {
41 int i;
42 for (i = 0; i < singleLevelDirectory.numFiles; i++) {
43 if (strcmp(singleLevelDirectory.files[i].name, filename) == 0) {
44 int j;
45 for (j = i; j < singleLevelDirectory.numFiles - 1; j++) {
46 singleLevelDirectory.files[j] = singleLevelDirectory.files[j + 1];
47 }
48 singleLevelDirectory.numFiles--;
49 printf("File ’%s’ deleted successfully from single-level directory\n",
,→ filename);
50 return;
51 }
52 }
53 printf("File ’%s’ not found in single-level directory\n", filename);
54 }
55

56 // Function to display files in a single-level directory


57 void displayFilesSingleLevel() {
58 printf("Files in single-level directory:\n");
59 int i;
60 for (i = 0; i < singleLevelDirectory.numFiles; i++) {
61 printf("%s\t%d bytes\n", singleLevelDirectory.files[i].name,
,→ singleLevelDirectory.files[i].size);
62 }
63 }
64

65 // Function to create a file in a two-level directory


66 void createFileTwoLevel(char* dirname, char* filename, int size) {
67 int i;
68 for (i = 0; i < MAX_FILES; i++) {
69 if (strcmp(twoLevelDirectory[i].name, dirname) == 0) {
70 if (twoLevelDirectory[i].numFiles < MAX_FILES) {
71 strcpy(twoLevelDirectory[i].files[twoLevelDirectory[i].numFiles].name,

Dept. of CSE(AI&ML), GSSSIETW, Mysuru-570016 Page 34


3rd Sem, B.E [CSE(AI&ML)] : Operating System IPCC [BCS303]

,→ filename);
72 twoLevelDirectory[i].files[twoLevelDirectory[i].numFiles].size =
,→ size;
73 twoLevelDirectory[i].numFiles++;
74 printf("File ’%s’ created successfully in directory ’%s’ of
,→ two-level directory\n", filename, dirname);
75 return;
76 } else {
77 printf("Cannot create file. Directory ’%s’ is full.\n", dirname);
78 return;
79 }
80 }
81 }
82 printf("Directory ’%s’ not found in two-level directory\n", dirname);
83 }
84

85 // Function to delete a file from a two-level directory


86 void deleteFileTwoLevel(char* dirname, char* filename) {
87 int i;
88 for (i = 0; i < MAX_FILES; i++) {
89 if (strcmp(twoLevelDirectory[i].name, dirname) == 0) {
90 int j;
91 for (j = 0; j < twoLevelDirectory[i].numFiles; j++) {
92 if (strcmp(twoLevelDirectory[i].files[j].name, filename) == 0) {
93 int k;
94 for (k = j; k < twoLevelDirectory[i].numFiles - 1; k++) {
95 twoLevelDirectory[i].files[k] = twoLevelDirectory[i].files[k
,→ + 1];
96 }
97 twoLevelDirectory[i].numFiles--;
98 printf("File ’%s’ deleted successfully from directory ’%s’ of
,→ two-level directory\n", filename, dirname);
99 return;
100 }
101 }
102 printf("File ’%s’ not found in directory ’%s’ of two-level
,→ directory\n", filename, dirname);
103 return;
104 }
105 }
106 printf("Directory ’%s’ not found in two-level directory\n", dirname);
107 }
108

109 // Function to display files in a two-level directory

Dept. of CSE(AI&ML), GSSSIETW, Mysuru-570016 Page 35


3rd Sem, B.E [CSE(AI&ML)] : Operating System IPCC [BCS303]

110 void displayFilesTwoLevel(char* dirname) {


111 int i;
112 for (i = 0; i < MAX_FILES; i++) {
113 if (strcmp(twoLevelDirectory[i].name, dirname) == 0) {
114 printf("Files in directory ’%s’ of two-level directory:\n", dirname);
115 int j;
116 for (j = 0; j < twoLevelDirectory[i].numFiles; j++) {
117 printf("%s\t%d bytes\n", twoLevelDirectory[i].files[j].name,
,→ twoLevelDirectory[i].files[j].size);
118 }
119 return;
120 }
121 }
122 printf("Directory ’%s’ not found in two-level directory\n", dirname);
123 }
124

125 int main() {


126 singleLevelDirectory.numFiles = 0;
127

128 int choice;


129 while (1) {
130 printf("\nDirectory Simulation\n");
131 printf("1. Single-level Directory - Create File\n");
132 printf("2. Single-level Directory - Delete File\n");
133 printf("3. Single-level Directory - Display Files\n");
134 printf("4. Two-level Directory - Create File\n");
135 printf("5. Two-level Directory - Delete File\n");
136 printf("6. Two-level Directory - Display Files\n");
137 printf("7. Exit\n");
138 printf("Enter your choice: ");
139 scanf("%d", &choice);
140

141 char filename[MAX_NAME_LENGTH], dirname[MAX_NAME_LENGTH];


142 int size;
143

144 switch (choice) {


145 case 1:
146 printf("Enter file name: ");
147 scanf("%s", filename);
148 printf("Enter file size (in bytes): ");
149 scanf("%d", &size);
150 createFileSingleLevel(filename, size);
151 break;
152 case 2:

Dept. of CSE(AI&ML), GSSSIETW, Mysuru-570016 Page 36


3rd Sem, B.E [CSE(AI&ML)] : Operating System IPCC [BCS303]

153 printf("Enter file name to delete: ");


154 scanf("%s", filename);
155 deleteFileSingleLevel(filename);
156 break;
157 case 3:
158 displayFilesSingleLevel();
159 break;
160 case 4:
161 printf("Enter directory name: ");
162 scanf("%s", dirname);
163 printf("Enter file name: ");
164 scanf("%s", filename);
165 printf("Enter file size (in bytes): ");
166 scanf("%d", &size);
167 createFileTwoLevel(dirname, filename, size);
168 break;
169 case 5:
170 printf("Enter directory name: ");
171 scanf("%s", dirname);
172 printf("Enter file name to delete: ");
173 scanf("%s", filename);
174 deleteFileTwoLevel(dirname, filename);
175 break;
176 case 6:
177 printf("Enter directory name: ");
178 scanf("%s", dirname);
179 displayFilesTwoLevel(dirname);
180 break;
181 case 7:
182 break;
183 }
184 }
185 }
186

187 /*Expected Output


188 Directory Simulation
189 1. Single-level Directory - Create File
190 2. Single-level Directory - Delete File
191 3. Single-level Directory - Display Files
192 4. Two-level Directory - Create File
193 5. Two-level Directory - Delete File
194 6. Two-level Directory - Display Files
195 7. Exit
196 Enter your choice: 1

Dept. of CSE(AI&ML), GSSSIETW, Mysuru-570016 Page 37


3rd Sem, B.E [CSE(AI&ML)] : Operating System IPCC [BCS303]

197 Enter file name: aiml


198 Enter file size (in bytes): 120
199 File ’aiml’ created successfully in single-level directory
200

201 Directory Simulation


202 1. Single-level Directory - Create File
203 2. Single-level Directory - Delete File
204 3. Single-level Directory - Display Files
205 4. Two-level Directory - Create File
206 5. Two-level Directory - Delete File
207 6. Two-level Directory - Display Files
208 7. Exit
209 Enter your choice: 3
210 Files in single-level directory:
211 aiml 120 bytes

Dept. of CSE(AI&ML), GSSSIETW, Mysuru-570016 Page 38

You might also like