6 15 3 5output
6 15 3 5output
4 5
Experiment 11
1. #include <stdio.h>
2. #include <stdlib.h>
3. #include <unistd.h>
4. #include <sys/types.h>
5. #include <sys/wait.h>
6.
7. int main() {
8. pid_t pid;
9.
10. // Create a child process
11. pid = fork();
12.
13. if (pid < 0) {
14. // Fork failed
15. fprintf(stderr, "Failed to create child process\n");
16. return 1;
17. } else if (pid == 0) {
18. // Child process
19. printf("Child process: Hello! I am the child process.\n");
20. exit(0);
21. } else {
22. // Parent process
23. wait(NULL); // Wait for the child process to complete
24. printf("Parent process: Child process has completed.\n");
25. printf("Parent process: Goodbye!\n");
26. return 0;
27. }
28.}
Experiment 12
#!/bin/bash
reverseNumber() {
local num=$1
local reversedNum=0
echo "$reversedNum"
}
reverseString() {
local str=$1
local reversedStr=""
echo "$reversedStr"
}
reversedNumber=$(reverseNumber "$number")
echo "Reversed number: $reversedNumber"
reversedString=$(reverseString "$string")
echo "Reversed string: $reversedString"
Output
Experiment 13
smallest=$num1
if (( num2 < smallest )); then
smallest=$num2
largest=$num1
Output
fi
fi
fi
fi
fi
fi
Experiment 14
Write script that prints names of all sub directories present in the current
directory.
#!/bin/bash
done
Output
fi
Experiment 15
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <fcntl.h>
int main() {
// Determine the maximum allocatable pages
long max_pages = sysconf(_SC_AVPHYS_PAGES);
printf("Maximum allocatable pages: %ld\n", max_pages);
return 0;
}
Experiment 7
Simulate all File Organization Techniques a) Single level directory b) Two level
directory
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct {
char name[MAX_NAME_LENGTH];
int location;
} File;
typedef struct {
char name[MAX_NAME_LENGTH];
int num_ les;
File les[MAX_FILES];
} Directory;
Directory singleLevelDirectory;
Directory twoLevelDirectory[MAX_FILES];
void initializeDirectories() {
singleLevelDirectory.num_ les = 0;
for (int i = 0; i < MAX_FILES; i++) {
twoLevelDirectory[i].num_ les = 0;
}
}
twoLevelDirectory[directoryIndex]. les[twoLevelDirectory[directoryIndex].nu
m_ les] = le;
twoLevelDirectory[directoryIndex].num_ les++;
printf("File '%s' added to Directory %d in Two Level Directory.\n",
name, directoryIndex);
} else {
printf("Directory %d in Two Level Directory is full. Cannot add le '%s'.
\n", directoryIndex, name);
}
}
void printSingleLevelDirectory() {
printf("\nSingle Level Directory:\n");
for (int i = 0; i < singleLevelDirectory.num_ les; i++) {
printf("File Name: %s, Location: %d\n",
singleLevelDirectory. les[i].name, singleLevelDirectory. les[i].location);
}
}
void printTwoLevelDirectory() {
printf("\nTwo Level Directory:\n");
for (int i = 0; i < MAX_FILES; i++) {
if (twoLevelDirectory[i].num_ les > 0) {
printf("Directory %d:\n", i);
for (int j = 0; j < twoLevelDirectory[i].num_ les; j++) {
printf("File Name: %s, Location: %d\n",
twoLevelDirectory[i]. les[j].name, twoLevelDirectory[i]. les[j].location);
}
}
}
}
int main() {
initializeDirectories();
return 0;
}
Experiment 8
typedef struct {
char name[MAX_NAME_LENGTH];
int start_block;
int length;
} File;
File les[MAX_FILES];
int num_ les = 0;
if (num_ les == 0) {
le.start_block = 0;
} else {
le.start_block = les[num_ les - 1].start_block + les[num_ les - 1].length;
}
void printSequentialAllocation() {
printf("\nSequential File Allocation:\n");
for (int i = 0; i < num_ les; i++) {
printf("File Name: %s, Start Block: %d, Length: %d\n", les[i].name,
les[i].start_block, les[i].length);
}
}
int main() {
addFileSequential("File1.txt", 100);
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
addFileSequential("File2.txt", 200);
addFileSequential("File3.txt", 150);
printSequentialAllocation();
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct {
char name[MAX_NAME_LENGTH];
int index_blocks[MAX_INDEX_BLOCKS];
int num_index_blocks;
} File;
File les[MAX_FILES];
int num_ les = 0;
void printIndexedAllocation() {
printf("\nIndexed File Allocation:\n");
for (int i = 0; i < num_ les; i++) {
printf("File Name: %s, Index Blocks: ", les[i].name);
for (int j = 0; j < les[i].num_index_blocks; j++) {
printf("%d ", les[i].index_blocks[j]);
}
printf("\n");
}
}
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
int main() {
int blocks1[] = {1, 2, 3};
addFileIndexed("File1.txt", blocks1, sizeof(blocks1) / sizeof(blocks1[0]));
printIndexedAllocation();
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct {
char name[MAX_NAME_LENGTH];
int start_block;
} File;
typedef struct {
int block_number;
int next_block;
} Block;
File les[MAX_FILES];
Block blocks[MAX_FILES];
int num_ les = 0;
int num_blocks = 0;
num_blocks += num_blocks;
void printLinkedAllocation() {
printf("\nLinked File Allocation:\n");
for (int i = 0; i < num_ les; i++) {
printf("File Name: %s\n", les[i].name);
printf("Blocks: ");
int current_block = les[i].start_block;
while (current_block != -1) {
printf("%d ", current_block);
current_block = blocks[current_block].next_block;
}
printf("\n");
}
}
int main() {
addFileLinked("File1.txt", 3);
addFileLinked("File2.txt", 5);
addFileLinked("File3.txt", 2);
printLinkedAllocation();
return 0;
}
fi
fi
fi
fi
fi
Experiment 9
Write a script to translate the string from capital letters to small and small
letters to capital using awk command.
#!/bin/bash
input_string="Hello World"
Output
Experiment 10
#!/bin/bash
done
done
Output
fi
fi
Experiment 6
a. FIFO
#include <stdio.h>
#de ne MAX_FRAMES 3
#de ne MAX_PAGES 20
return page_faults;
}
int main() {
int pages[MAX_PAGES] = {1, 3, 0, 3, 5, 6, 3, 7, 8, 3, 6, 8, 9, 1, 0, 3, 6, 2, 3, 0};
int num_pages = sizeof(pages) / sizeof(pages[0]);
return 0;
}
fi
B. LRU
#include <stdio.h>
#de ne MAX_FRAMES 3
#de ne MAX_PAGES 20
return lru_page_index;
}
counter_value++;
return page_faults;
}
int main() {
int pages[MAX_PAGES] = {1, 3, 0, 3, 5, 6, 3, 7, 8, 3, 6, 8, 9, 1, 0, 3, 6, 2, 3, 0};
int num_pages = sizeof(pages) / sizeof(pages[0]);
return 0;
}
C. Optimal
#include <stdio.h>
#include <limits.h>
#de ne MAX_FRAMES 3
#de ne MAX_PAGES 20
int ndOptimal(int pages[], int frames[], int start_index, int num_frames, int
num_pages) {
int optimal_index = -1;
int farthest_page_index = -1;
if (!found) {
return i;
}
}
return optimal_index;
}
return page_faults;
}
int main() {
int pages[MAX_PAGES] = {1, 3, 0, 3, 5, 6, 3, 7, 8, 3, 6, 8, 9, 1, 0, 3, 6, 2, 3,
0};
int num_pages = sizeof(pages) / sizeof(pages[0]);
return 0;
}
fi