1. a.
Install any flavor of windows operating system on top of any bare metal by creating necessary partitions for OS and
user space. (80)
b. Create a directory on your own and include two files and list out the files that are present in that directory using the
necessary UNIX commands.
Answer for 1A:
Windows Installation Procedure
1. Prepare Installation Media: Create a bootable USB with Windows 10/11 ISO using Rufus.
2. Boot from USB: Insert USB, restart, enter BIOS/UEFI (F2/Del), set USB as boot device.
3. Partitioning:
o Choose "Custom Install" in Windows setup.
o Delete existing partitions to create unallocated space.
o Create a 100 GB partition for OS.
o Create a second partition for user data (e.g., remaining space).
4. Install Windows: Select OS partition, follow setup prompts.
5. Format User Partition: Post-install, format user partition (NTFS) via Disk Management.
Expected Output:
• Windows boots successfully. Disk Management shows two partitions: C: (100 GB, OS) and D: (user data,
formatted as NTFS).
Explanation:
• Procedural task for installing Windows with separate OS and user partitions.
• Output is the successful boot and partitioned disk.
1b. Create a directory, add two files, and list them using UNIX commands.
Answer :
mkdir mydir touch mydir/file1.txt mydir/file2.txt ls mydir
Output:
file1.txt file2.txt
Explanation:
• mkdir mydir: Creates directory mydir.
• touch: Creates file1.txt and file2.txt.
• ls mydir: Lists the files.
• Output shows the two created files.
2a. Count lines, characters, and words in a file using UNIX command.
Ans:
wc -l -c -w sample.txt
Sample Input (File sample.txt):
Hello world
This is a test
Output:
2 25 7 sample.txt
Explanation:
• wc -l: Counts 2 lines.
• wc -c: Counts 25 characters (including newlines).
• wc -w: Counts 7 words.
• Output format: lines, words, characters, filename.
2b. Create a process and print its process ID and parent process ID.
Ans:
#include <stdio.h>
#include <unistd.h>
int main() {
pid_t pid = getpid();
pid_t ppid = getppid();
printf("Process ID: %d\n", pid);
printf("Parent Process ID: %d\n", ppid);
return 0;
**Output**:
```
Process ID: 12345
Parent Process ID: 12340
```
Explanation:
• getpid(): Returns current process ID (e.g., 12345).
• getppid(): Returns parent process ID (e.g., 12340, likely the shell).
• Sample PIDs are illustrative.
2c. C program for FCFS scheduling with process ID, average waiting time, and turnaround time.
Ans:
Check print out.
3a. Find a file in a directory and print unique lines.
Ans:
find ./ -name "sample.txt" -exec sort -u {} ;
Sample Input (File sample.txt):
hello
world
hello
test
Output:
hello
test
world
Explanation:
• find: Locates sample.txt.
• sort -u: Sorts and removes duplicates.
• Output lists unique lines alphabetically.
3b. Identify parent or child process using system calls.
Ans :
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
int main() {
pid_t pid = fork();
if (pid < 0) {
printf("Fork failed\n");
} else if (pid == 0) {
printf("Child Process: PID=%d, Parent PID=%d\n", getpid(), getppid());
} else {
printf("Parent Process: PID=%d, Child PID=%d\n", getpid(), pid);
return 0;
**Output**:
```
Parent Process: PID=12350, Child PID=12351
Child Process: PID=12351, Parent PID=12350
```
Explanation:
• fork(): Creates child process.
• Parent and child print their PIDs and related PIDs.
• Sample PIDs are illustrative.
3c. C program for SJF scheduling.
Check notes
4a. Check if a remote host is responding.
Ans:
ping -c 4 google.com
Output:
PING google.com (142.250.190.14) 56(84) bytes of data.
64 bytes from 142.250.190.14: icmp_seq=1 ttl=117 time=14.2 ms
64 bytes from 142.250.190.14: icmp_seq=2 ttl=117 time=14.5 ms
64 bytes from 142.250.190.14: icmp_seq=3 ttl=117 Grok timeout
Explanation:
• ping -c 4: Sends 4 packets to google.com.
• Output shows response times and packet loss (sample times are illustrative).
4b. Shell program to count vowels in a line of text.
#!/bin/bash
read -p "Enter a string: " str
echo "$str" | grep -o -i "[aeiou]" | wc -l
How It Works:
1. read -p prompts the user for input.
2. grep -o -i "[aeiou]" finds all vowels (-i makes it case-insensitive).
3. wc -l counts the number of vowels.
Steps to Execute in Ubuntu:
1. Save the script as vowel_count.sh.
2. Give execution permission:
bash
chmod +x vowel_count.sh
3. Run the script:
bash
./vowel_count.sh
4. Enter a string, and it will display the vowel count.
4c. C program for IPC using shared memory.
Ans:
#include <stdio.h>
#include <sys/shm.h>
#include <sys/types.h>
#include <unistd.h>
#include <string.h>
#include <sys/wait.h>
int main() {
int shmid = shmget(IPC_PRIVATE, 1024, 0666 | IPC_CREAT);
char *shm = shmat(shmid, NULL, 0);
pid_t pid = fork();
if (pid == 0) {
strcpy(shm, "Hello from child!");
shmdt(shm);
} else {
wait(NULL);
printf("Parent received: %s\n", shm);
shmdt(shm);
shmctl(shmid, IPC_RMID, NULL);
return 0;
**Output**:
```
Parent received: Hello from child!
```
Explanation:
• Child writes to shared memory.
• Parent reads after child terminates.
• wait ensures parent reads after child writes.
5a. Print last 10 lines of a file
Ans:
tail -n 10 sample.txt
Sample Input (File sample.txt with 12 lines):
Line 1
Line 2
Line 3
Line 4
Line 5
Line 6
Line 7
Line 8
Line 9
Line 10
Line 11
Line 12
Output:
Line 3
Line 4
Line 5
Line 6
Line 7
Line 8
Line 9
Line 10
Line 11
Line 12
Explanation:
• tail -n 10: Prints last 10 lines (lines 3–12).
5b. Shell program for sum and average of four integers.
Ans:
#!/bin/bash
echo "Enter four integers:"
read a b c d
sum=$((a + b + c + d))
avg=$((sum / 4))
echo "Sum: $sum"
echo "Average: $avg"
**Sample Input**:
```
Enter four integers:
10 20 30 40
```
**Output**:
```
Sum: 100
Average: 25
```
Explanation:
• Sums: 10+20+30+40=100.
• Average: 100/4=25 (integer division).
5c . C program for deadlock detection.
Check notes write the Bankers Algorithm
6a. List logged-in users and print current month’s calendar.
Ans:
who cal
Output:
user1 pts/0 2025-05-13 10:00 (192.168.1.100)
user2 pts/1 2025-05-13 10:15 (192.168.1.101)
May 2025
Su Mo Tu We Th Fr Sa
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
Explanation:
• who: Lists logged-in users.
• cal: Shows May 2025 calendar.
6b. Shell program for simple and compound interest.
#!/bin/bash
echo "Enter principal, rate, time:"
read p r t
si=$((p * r * t / 100))
ci=$(echo "$p * (1 + $r/100)^$t - $p" | bc -l)
printf "Simple Interest: %.2f\n" $si
printf "Compound Interest: %.2f\n" $ci
**Sample Input**:
```
Enter principal, rate, time:
1000 5 2
```
**Output**:
```
Simple Interest: 100.00
Compound Interest: 102.50
```
Explanation:
Simple Interest: (1000 * 5 * 2) / 100 = 100.
Compound Interest: 1000 * (1 + 5/100)^2 - 1000 = 102.50.
6c. C program for Round Robin scheduling.
Check Notes :
7a. Rename a file.
Ans:
mv oldname.txt newname.txt
Output:
• No output. Verify with:
ls
newname.txt
Explanation:
• mv: Renames oldname.txt to newname.txt.
• ls confirms the rename.
7b. Shell program for area and circumference of a circle.
Ans:
#!/bin/bash
echo "Enter radius:"
read r
area=$(echo "3.14 * $r * $r" | bc)
circ=$(echo "2 * 3.14 * $r" | bc)
printf "Area: %.2f\n" $area
printf "Circumference: %.2f\n" $circ
**Sample Input**:
```
Enter radius:
```
**Output**:
```
Area: 78.50
Circumference: 31.40
```
Explanation:
• Area: π * 5^2 = 78.50.
• Circumference: 2 * π * 5 = 31.40.
7c. C program for Priority scheduling.
Check Notes
8a. Create a file with content and display it.
bash
echo "Sample content" > myfile.txt && cat myfile.txt
Explanation
1. echo "Sample content" > myfile.txt → Creates myfile.txt and writes "Sample content" into it.
2. cat myfile.txt → Displays the content of the file.
Expected Output
Sample content
8b. C program using wait system call.
Check Notes Or use this :
#include <stdio.h>
#include <unistd.h>
#include <sys/wait.h>
int main() {
pid_t pid = fork();
if (pid == 0) {
printf("Child process running\n");
sleep(2);
printf("Child process exiting\n");
} else {
printf("Parent waiting for child\n");
wait(NULL);
printf("Child terminated, parent exiting\n");
return 0;
**Output**:
```
Parent waiting for child
Child process running
Child process exiting
Child terminated, parent exiting
```
Explanation:
fork: Creates child.
wait: Parent waits for child to terminate.
Child sleeps for 2 seconds.
8c. C program for semaphore synchronization.
Check Notes :
Explanation:
• Semaphore ensures mutual exclusion.
• Threads access critical section one at a time.
• Compile with -pthread.
9a. Shell program to display student grades.
#!/bin/bash
echo "Enter student name:"
read name
echo "Enter marks in three subjects:"
read m1 m2 m3
total=$((m1 + m2 + m3))
avg=$((total / 3))
if [ $avg -ge 90 ]; then
grade="A"
elif [ $avg -ge 80 ]; then
grade="B"
elif [ $avg -ge 70 ]; then
grade="C"
else
grade="D"
fi
echo "Student: $name, Total: $total, Average: $avg, Grade: $grade"
**Sample Input**:
```
Enter student name:
John
Enter marks in three subjects:
85 90 88
```
**Output**:
```
Student: John, Total: 263, Average: 87, Grade: B
```
Explanation:
• Total: 85+90+88=263.
• Average: 263/3=87.
• Grade: 87 → B (80-89).
9b. C program for thread synchronization.
#include <stdio.h>
#include <pthread.h>
pthread_mutex_t mutex;
int shared = 0;
void* increment(void* arg) {
for (int i = 0; i < 1000; i++) {
pthread_mutex_lock(&mutex);
shared++;
pthread_mutex_unlock(&mutex);
return NULL;
int main() {
pthread_mutex_init(&mutex, NULL);
pthread_t t1, t2;
pthread_create(&t1, NULL, increment, NULL);
pthread_create(&t2, NULL, increment, NULL);
pthread_join(t1, NULL);
pthread_join(t2, NULL);
printf("Final shared value: %d\n", shared);
pthread_mutex_destroy(&mutex);
return 0;
**Output**:
```
Final shared value: 2000
```
Explanation:
• Mutex ensures atomic increments.
• Two threads increment shared 1000 times each.
• Compile with -pthread.
10a. Print manual page of a command.
man ls
Output (Abbreviated):
LS(1) User Commands LS(1)
NAME
ls - list directory contents
SYNOPSIS
ls [OPTION]... [FILE]...
DESCRIPTION
List information about the FILEs (the current directory by default).
Sort entries alphabetically if none of -cftuvSUX nor --sort is specified.
...
Explanation:
• man ls: Displays ls manual page.
10b. Shell program for Fibonacci series.
#!/bin/bash
echo "Enter number of terms:"
read n
a=0
b=1
echo "Fibonacci series:"
for ((i=0; i<n; i++)); do
echo -n "$a "
c=$((a + b))
a=$b
b=$c
done
echo
**Sample Input**:
```
Enter number of terms:
```
**Output**:
```
Fibonacci series:
011235
```
Explanation:
• Generates 6 Fibonacci numbers: 0, 1, 1, 2, 3, 5.
10c. C program for paging in memory management.
Check Notes
11a. List and remove a directory.
Command to List a Directory’s Contents
bash
ls dirname
Example:
bash
ls test_directory
This will display the contents of test_directory.
Command to Remove a Directory and Its Contents
bash
rm -r dirname
Example:
bash
rm -r test_directory
• The -r (recursive) flag ensures the directory and all its files are deleted.
If you need confirmation before deleting, use:
bash
rm -ri test_directory
This will prompt for confirmation before deleting each file.
11b. Shell program for roots of a quadratic equation.
#!/bin/bash
echo "Enter coefficients a, b, c:"
read a b c
d=$(echo "$b * $b - 4 * $a * $c" | bc)
if [ $(echo "$d < 0" | bc) -eq 1 ]; then
echo "Roots are imaginary"
else
r1=$(echo "(-$b + sqrt($d)) / (2 * $a)" | bc -l)
r2=$(echo "(-$b - sqrt($d)) / (2 * $a)" | bc -l)
printf "Root 1: %.2f\nRoot 2: %.2f\n" $r1 $r2
fi
**Sample Input**:
```
Enter coefficients a, b, c:
156
```
**Output**:
```
Root 1: -2.00
Root 2: -3.00
```
Explanation:
• Equation: x^2 + 5x + 6 = 0.
• Discriminant: 5^2 - 416 = 1.
• Roots: (-5 ± √1) / 2 = -2, -3.
11c. C program for FIFO page replacement.
Check Notes
12a. Print output to terminal and list running processes.
echo "Hello" ps aux
Output (Abbreviated):
Hello
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
user1 1234 0.0 0.1 12345 6789 pts/0 Ss 10:00 0:01 bash
user1 1235 0.0 0.0 12346 6790 pts/0 R+ 10:01 0:00 ps aux
Explanation:
• echo: Prints “Hello”.
• ps aux: Lists processes.
12b. Shell program to check if a number is positive or negative.
#!/bin/bash
echo "Enter a number:"
read num
if [ $num -gt 0 ]; then
echo "Positive"
elif [ $num -lt 0 ]; then
echo "Negative"
else
echo "Zero"
fi
**Sample Input**:
```
Enter a number:
-5
```
**Output**:
```
Negative
```
Explanation:
• Checks if -5 is positive, negative, or zero.
12c. C program for LRU page replacement.
Check notes
13a. Shell script to display digits in odd positions.
#!/bin/bash
echo "Enter a number:"
read num
echo $num | grep -o . | awk 'NR%2==1'
**Sample Input**:
```
Enter a number:
12345
```
**Output**:
```
```
Explanation:
• grep -o .: Splits digits.
• awk 'NR%2==1': Prints odd-positioned digits (1, 3, 5).
13b. C program for Optimal page replacement.
Check Notes
14a. Shell program for sum of two numbers using a function.
#!/bin/bash
sum() {
echo $(($1 + $2))
echo "Enter two numbers:"
read a b
result=$(sum $a $b)
echo "Sum: $result"
**Sample Input**:
```
Enter two numbers:
10 20
```
**Output**:
```
Sum: 30
```
Explanation:
• sum function adds 10 and 20.
14b. Shell program for sequential file allocation
Check Notes
15a. Display block number at the beginning of each line.
nl sample.txt
Sample Input (File sample.txt):
Line 1
Line 2
Line 3
Output:
1 Line 1
2 Line 2
3 Line 3
Explanation:
• nl: Numbers lines starting from 1.
15b. Shell program to check if a number is prime.
#!/bin/bash
echo "Enter a number:"
read n
if [ $n -lt 2 ]; then
echo "Not prime"
exit
fi
for ((i=2; i*i<=n; i++)); do
if [ $((n % i)) -eq 0 ]; then
echo "Not prime"
exit
fi
done
echo "Prime"
**Sample Input**:
```
Enter a number:
17
```
**Output**:
```
Prime
```
Explanation:
• Checks if 17 is divisible by numbers up to √17.
• No divisors, so prime.
15c. C program for random file access.
#include <stdio.h>
int main() {
FILE *fp = fopen("file.txt", "r+");
if (!fp) {
printf("File not found\n");
return 1;
int pos;
printf("Enter position to read/write: ");
scanf("%d", &pos);
fseek(fp, pos, SEEK_SET);
char data[100];
printf("Enter data to write: ");
scanf("%s", data);
fputs(data, fp);
fseek(fp, pos, SEEK_SET);
char buffer[100];
fgets(buffer, 100, fp);
printf("Data at position %d: %s\n", pos, buffer);
fclose(fp);
return 0;
**Sample Input** (Initial `file.txt`: empty or exists):
```
Enter position to read/write: 0
Enter data to write: Hello
```
**Output**:
```
Data at position 0: Hello
```
Explanation:
• Writes “Hello” at position 0, reads it back.
• Assumes file.txt is writable.
16a. Install Linux as a guest OS on Windows.
Linux Guest OS Installation Procedure
1. Install VirtualBox: Download and install VirtualBox on Windows.
2. Download Linux ISO: Get Ubuntu ISO from ubuntu.com.
3. Create VM:
o Open VirtualBox, click “New.”
o Name: Ubuntu, Type: Linux, Version: Ubuntu (64-bit).
o Allocate 2 GB RAM, 20 GB virtual hard disk (VDI, dynamically allocated).
4. Configure VM:
o Settings > Storage: Attach Ubuntu ISO.
o Adjust CPU (2 cores), display settings.
5. Install Linux:
o Start VM, boot from ISO.
o Follow Ubuntu installer: Select language, keyboard, install options, create user.
6. Post-Installation: Install Guest Additions for better integration (Settings > Insert Guest Additions CD).
Expected Output:
• Ubuntu boots in VirtualBox. Desktop environment loads, showing welcome screen. User logs in with
created credentials. Guest Additions enhance resolution and clipboard sharing.
Explanation:
• Procedural task for installing Ubuntu in VirtualBox.
• Output is successful VM boot and Ubuntu desktop.
16b. UNIX command to create a directory.
mkdir dirname
Output:
• No output. Verify with:
ls
dirname
Explanation:
• mkdir dirname: Creates dirname.
17. C program for FCFS disk scheduling.
Check Notes\
18. C program for SSTF disk scheduling.
Check Notes\
19a. Get information from DNS server.
nslookup google.com
Output:
Server: 8.8.8.8
Address: 8.8.8.8#53
Non-authoritative answer:
Name: google.com
Address: 142.250.190.14
Explanation:
• nslookup: Queries DNS for google.com’s IP.
19b. Shell script for area of a triangle.
#!/bin/bash
echo "Enter base and height:"
read b h
area=$(echo "0.5 * $b * $h" | bc)
printf "Area: %.2f\n" $area
**Sample Input**:
```
Enter base and height:
10 5
**Output**:
Area: 25.00
Explanation:
• Area: 0.5 * 10 * 5 = 25.
19c. C program for Best Fit allocation.
#include <stdio.h>
void bestFit(int blockSize[], int blocks, int processSize[], int processes) {
int allocation[processes];
for (int i = 0; i < processes; i++) {
int bestIdx = -1;
for (int j = 0; j < blocks; j++) {
if (blockSize[j] >= processSize[i] && (bestIdx == -1 || blockSize[j] < blockSize[bestIdx])) {
bestIdx = j;
}
if (bestIdx != -1) {
allocation[i] = bestIdx;
blockSize[bestIdx] -= processSize[i];
} else {
allocation[i] = -1;
printf("\nProcess\tSize\tBlock\n");
for (int i = 0; i < processes; i++) {
printf("%d\t%d\t", i + 1, processSize[i]);
if (allocation[i] != -1)
printf("%d\n", allocation[i] + 1);
else
printf("Not Allocated\n");
int main() {
int blockSize[] = {100, 500, 200, 300, 600};
int processSize[] = {212, 417, 112, 426};
int blocks = sizeof(blockSize) / sizeof(blockSize[0]);
int processes = sizeof(processSize) / sizeof(processSize[0]);
printf("Best Fit Memory Allocation:\n");
bestFit(blockSize, blocks, processSize, processes);
return 0;
How to Compile & Run in Ubuntu
gcc best_fit.c -o best_fit
./best_fit
Expected Output
Process Size Block
1 212 3
2 417 2
3 112 3
4 426 Not Allocated
20a. Shell program to find the smallest digit in a number.
#!/bin/bash
echo "Enter a number:"
read num
smallest=$(echo $num | grep -o . | sort | head -1)
echo "Smallest digit: $smallest"
**Sample Input**:
```
Enter a number:
5823
```
**Output**:
Smallest digit: 2
Explanation:
• Splits 5823, sorts digits, takes smallest (2).
20b. C program for Worst Fit allocation.
#include <stdio.h>
void worstFit(int blockSize[], int blocks, int processSize[], int processes) {
int allocation[processes];
for (int i = 0; i < processes; i++) {
int worstIdx = -1;
for (int j = 0; j < blocks; j++) {
if (blockSize[j] >= processSize[i] && (worstIdx == -1 || blockSize[j] > blockSize[worstIdx])) {
worstIdx = j;
if (worstIdx != -1) {
allocation[i] = worstIdx;
blockSize[worstIdx] -= processSize[i];
} else {
allocation[i] = -1;
printf("\nProcess\tSize\tBlock\n");
for (int i = 0; i < processes; i++) {
printf("%d\t%d\t", i + 1, processSize[i]);
if (allocation[i] != -1)
printf("%d\n", allocation[i] + 1);
else
printf("Not Allocated\n");
int main() {
int blockSize[] = {100, 500, 200, 300, 600};
int processSize[] = {212, 417, 112, 426};
int blocks = sizeof(blockSize) / sizeof(blockSize[0]);
int processes = sizeof(processSize) / sizeof(processSize[0]);
printf("Worst Fit Memory Allocation:\n");
worstFit(blockSize, blocks, processSize, processes);
return 0;
How to Compile & Run in Ubuntu
gcc worst_fit.c -o worst_fit
./worst_fit
Expected Output
Process Size Block
1 212 5
2 417 2
3 112 5
4 426 Not Allocated
21. C program for C-LOOK disk scheduling.
Check Notes
22.C program for LOOK disk scheduling.
Check Notes
23a. Shell program to find the smallest of two numbers using a function.
#!/bin/bash
smallest() {
if [ $1 -lt $2 ]; then
echo $1
else
echo $2
fi
echo "Enter two
23b. C program for implementing contiguous file allocation strategy.
#include <stdio.h>
#define MAX_FILES 3
struct File {
char name[20];
int startBlock;
int size;
};
int main() {
struct File files[MAX_FILES];
printf("Enter details for %d files:\n", MAX_FILES);
int nextBlock = 0;
for (int i = 0; i < MAX_FILES; i++) {
printf("File %d name: ", i + 1);
scanf("%s", files[i].name);
printf("Size (blocks): ");
scanf("%d", &files[i].size);
files[i].startBlock = nextBlock;
nextBlock += files[i].size;
printf("\nFile Allocation:\n");
printf("File\tStart Block\tSize\n");
for (int i = 0; i < MAX_FILES; i++) {
printf("%s\t%d\t\t%d\n", files[i].name, files[i].startBlock, files[i].size);
return 0;
Expected Output Example
Enter details for 3 files:
File 1 name: file1
Size (blocks): 10
File 2 name: file2
Size (blocks): 20
File 3 name: file3
Size (blocks): 5
File Allocation:
File Start Block Size
file1 0 10
file2 10 20
file3 30 5
24. C program for implementing SCAN disk scheduling strategy.
Check Notes
25. C program for implementing C-SCAN disk scheduling strategy.
Check Notes
26a. Create two files and move them into a directory named ‘dir1’ using UNIX commands.
touch file1.txt file2.txt mkdir dir1 mv file1.txt file2.txt dir1 ls dir1
Output:
file1.txt file2.txt
Explanation:
• touch: Creates file1.txt and file2.txt.
• mkdir: Creates dir1.
• mv: Moves both files to dir1.
• ls dir1: Confirms the files are in dir1.
26b. Shell script for converting temperature from Fahrenheit to Celsius.
#!/bin/bash
echo "Enter temperature in Fahrenheit:"
read f
c=$(echo "($f - 32) * 5 / 9" | bc -l)
printf "Temperature in Celsius: %.2f\n" $c
**Sample Input**:
Enter temperature in Fahrenheit:
98.6
**Output**:
Temperature in Celsius: 37.00
Explanation:
• Formula: (°F - 32) * 5/9.
• 98.6°F = (98.6 - 32) * 5/9 = 37°C.
26c. C program for implementing linked file allocation strategy.
Check Notes