Os Lab Manual
Os Lab Manual
1
INSTITUTE VISION AND MISSION
VISION
MISSION
VISION
To impart quality education for producing highly talented globally recognizable techno carts
and entrepreneurs with innovative ideas in computer science and engineering to meet industrial
needs and societal expectations
MISSION
2
PROGRAM EDUCATIONAL OBJECTIVES (PEOs)
Graduates of B. Tech in computer science and Engineering Program shall be able to
PEO1: Strong foundation of knowledge and skills in the field of Computer Science and
Engineering.
PEO2: Pr ovide solutions to challenging problems in their profession by applying computer
engineering theory and practices.
PEO3: Produce leadership and are effective in multidisciplinary environment.
3
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
PROGRAM OUTCOMES
1. Engineering Knowledge: Apply the knowledge of mathematics, science, engineering
fundamentals, and an engineering specialization to the solution of complex engineering
problems.
2. Problem Analysis: Identify, formulate, research literature, and analyze complex
engineering problems reaching substantiated conclusions using first principles of mathematics,
natural sciences, and engineering sciences.
3. Design/Development of Solutions: Design solutions for complex engineering problems and
design system components or processes that meet the specified needs with appropriate
consideration for the public health and safety, and the cultural, societal, and environmental
considerations.
4. Conduct Investigations of Complex Problems: Use research-based knowledge and
research methods including design of experiments, analysis and interpretation of data, and
synthesis of the information to provide valid conclusions.
5. Modern Tool Usage: Create, select, and apply appropriate techniques, resources, and
modern engineering and IT tools including prediction and modelling to complex engineering
activities with an understanding of the limitations.
6. The Engineer and Society: Apply reasoning informed by the contextual knowledge to
assess societal, health, safety, legal and cultural issues and the consequent responsibilities
relevant to the professional engineering practice.
7. Environment and Sustainability: Understand the impact of the professional engineering
solutions in societal and environmental contexts, and demonstrate the knowledge of, and need
for sustainable development.
8. Ethics: Apply ethical principles and commit to professional ethics and responsibilities and
norms of the engineering practice.
9. Individual and Team Work: Function effectively as an individual, and as a member or
leader in diverse teams, and in multidisciplinary settings.
10. Communication: Communicate effectively on complex engineering activities with the
engineering community and with society at large, such as, being able to comprehend and write
effective reports and design documentation, make effective presentations, give and receive clear
instructions.
11. Project Management and Finance: Demonstrate knowledge and understanding of the
engineering and management principles and apply these to one’s own work, as a member
and leader in a team, to manage projects and in multidisciplinary environments
12. Life-Long Learning: Recognize the need for, and have the preparation and ability to
engage in independent and life-long learning in the broadest context of technological change.
COURSE OBJECTIVES
• To learn about UNIX/LINUX operating system environment.
• To learn about system calls for UNIX/LINUX Operating System.
• To understand resource management policies and mechanisms and their performance evaluation.
• To study and implement various mechanisms used for managing processes, including process
creation, process scheduling, and inter-process communication (IPC) via system calls.
• To provide students with a hands-on understanding of key OS concepts such as scheduling
algorithms, page replacement, deadlock management, disk scheduling, and memory
management.
• The student develops skill in writing C programs using system calls for process management,
inter process communication and other aspects.
• The student learns to simulate OS resource management aspects like process scheduling, page
replacement, disk scheduling, free space management and others to evaluate performance.
• Develop programs that simulate OS process scheduling algorithms, including FCFS (First-
Come, First-Served), SJF (Shortest Job First), and Round Robin.
• Write C programs to simulate free space management techniques, allowing students to
understand how the OS handles free memory or disk space.
1. Students are advised to come to the laboratory at least 5 minutes before (to the starting time),
those who come after 5 minutes will not be allowed into the lab.
2. Plan your task properly much before to the commencement, come prepared to the lab with the
synopsis / program / experiment details.
3. Student should enter into the laboratory with:
a. Laboratory observation notes with all the details (Problem statement, Aim, Algorithm,
Procedure, Program, Expected Output, etc.,) filled in for the lab session.
b. Laboratory Record updated up to the last session experiments and other utensils (if any)
needed in the lab.
c. Proper Dress code and Identity card.
4. Sign in the laboratory login register, write the TIME-IN, and occupy the computer system
allotted to you by the faculty.
5. Execute your task in the laboratory, and record the results / output in the lab observation note
book, and get certified by the concerned faculty.
6. All the students should be polite and cooperative with the laboratory staff, must maintain the
discipline and decency in the laboratory.
7. Computer labs are established with sophisticated and high end branded systems, which should
be utilized properly.
8. Students / Faculty must keep their mobile phones in SWITCHED OFF mode during the lab
sessions. Misuse of the equipment, misbehaviors with the staff and systems etc., will attract
severe punishment.
9. Students must take the permission of the faculty in case of any urgency to go out; if anybody
found loitering outside the lab / class without permission during working hours will be treated
seriously and punished appropriately.
10. Students should LOG OFF/ SHUT DOWN the computer system before he/she leaves the lab
after completing the task (experiment) in all aspects. He/she must ensure the system / seat is kept
properly
MODULE1
1. OS lab familiarization, Home Assignment on Unix commands, Vi editor
2. Simple shell programming exercises
3. Shell programming using decision making constructs, loop
constructs, file and directory manipulation
4. Simple C programs using command line arguments, system calls,
library function calls, make utility
5. C programs using system call to create processes and study parent,
child process mechanism
6. C programs to create process chaining, spawning
7. C programs to error handling using errno(), perror() function
8. C programs to use pipe system call for inter process communication
MODULE II
4. C Programs to simulate free space management (first fit, best fit, worst fit).
References:
TABLE OF CONTENTS
SNO CONTENT PAGE NO
MODULE -1
OS Introduction
1. 14-19
OS lab familiarization, Home Assignment on Unix commands,
Vi editor
2. 20-23
Simple shell programming exercises
3. 24-30
Shell programming using decision making
constructs, loop constructs, file and
directory manipulation
MODULE-2
2 55-56
C programs to study page replacement
implementing FIFO, Optimal, and LRU page
replacement algorithms.
4 73-81
C Programs to simulate free space management (first fit, best fit,
worst fit).
5 82-87
C programs to study disk scheduling algorithms (i.e., SCAN,
SSTF, LOOK, etc.,)
88-91
Viva Questions
OPERATING SYSTEM
Introduction : A computer system can be divided into four components
. Hardware
. Operating system
. System programs word processor spreadsheets, Accounting software.
. Application programs.
In 1960s definition of an operating system is software. Is software that controls the hardware. However, today
due to microcode, we need a better definition on. On we see an operating system as the program that make a
hardware use. In brief on operating system is the set of programs that controls the computer .
An operating system is software that creates a relation between the user software and hardware. So it is an
interface between. The all the computers need baskets. Software known as operating system to function.
The os acts as an interface between the user application programs, hardware and the system peripherals. The
os acts as in the first software to be loaded when a computer starts up. The entire application programs are
loaded after the os.
Types of operating system :
. Single user : If the single user operating system is loaded in computers memory The computer would be
able to handle one user at a time .
. Multi user. : If the multi user operating system is loaded in computers memory, the. Computer would be able
to handle more than one user at a time.
. Network.:If the network operating system is loaded in computers memory, the computer. Would be able to
handle more than one computer at a time.
Command prompt interface:
Operating system provides a text based interface called common prompt from the Command prompt.
Command can be. Issued to perform file and disk management end to run programs. Result of these commands
are presented to the users as text messages.
C: \> -
The command prompt can be an alphabet followed by one: one.> and one blinking element called cursor.
Microsoft Windows XP version (5.1. .2600)
(c) Copyright 1985 to 2001 Microsoft Corp.
C: \00 Comments and settings \ Rana Shankar)c : \
C: \ He is not recognized as an internal or external command. Separable program or batch file.
MODULE-1
1. OS LAB FAMILIARIZATION, HOME ASSIGNMENT ON UNIX COMMANDS, VI
EDITOR
1. Command 1 : PWD
This command refers to the present working directory in which you are operating. In simpler
words, in which your terminal is open to check PWD, execute the PWD keyboard in your
terminal and hit enter the command of PWD is written below along with the result of that
command.
/home/adnan
2. Command 2 : dir
This DIR Command is used to print all the available directories in the present working
directory.
A top downloads music, public videos, document file, text, pictures, templates
Adnan @ adnan : $
3. Command 3 : ls
This command is used to list down all the directories in files inside the present working
directory. This command. Can be executed as shown below.
Desktop, downloads ,music, public videos, documents ,file text pictures, templates.
This ls command supports various flags. And each flag has same specific role in printing the
directories or files of the current working directory.
To print the detail information of the files or directories, the -al flag is used with the LS
command.
Total 100
Desktop, downloads, music ,public videos ,download file text, pictures, templates.
./ Desktop
./ Documents.
./ Downloads.
./ Music.
./ Pictures.
./ Public.
./ Templates.
./ Videos.
Adnan @ adnan : $
4. Command 4 : cd
One of the most used comments of Ubuntu. You can change the directories in the terminal
using the cd command. For instance, the following command will change the pwd to desktop.
There are multiple uses of this command. One of can change the present directory to root
directory on home directory using this command. When you open a fresh terminal, you are in
the home directory.
5. Command 5 : touch
This Ubuntu command can be used to create a new file as well as one can use it to change the
time lamp of any file the command given below will create a new text time in Pwd.
Adnan @ adnan : $ ls
Adnan @ adnan : $
6. Command 6 : Cat
This command is used to show the content of any file. For instance, the following command
will display the content inside file.text.
Adnan @ adnan : $
7. Command 7 :mkdir
The above mentioned command will take a directory in your pwd. For example, the following
command will make directory new in Pwd.
Desktops , downloads, file text ,new ,pictures ,documents file text, music
Adnan @ adnan : $
8. Command 8 : rm
This remove command is used to remove the specific files from a directory. For instance, below
mentioned command would remove the test text file from the pwd.
Desktop , downloads, file text, pictures, templates, downloads, music ,public text.
SANKETIKA VIDYA PARISHAD ENGINEERING COLLEGE 16
DEPARTEMENT OF COMPUTER SCIENCE AND ENGINEERING
Are you can remove the empty directory as the command given to remove the test directory.
9. Command 9 : cp
The CP Command will help you to copy any file on folder to any directory
10 .Command 10 : mv
You can use this command to move files around the computer, and you can also rename files
or directories inside a specific directory. The command given below will not the file 2.text to
directory.
STUDY OF VI EDITOR :
VI editor : The VI editor visual editor is screen editor, which is available on almost all unit
systems. Vi has no means, but instead uses the combination of keystrokes in order to
accomplish the commands.
Models of VI editor :
Command mode
Commands :
Y (yonk\copy)
C (change)
E (end of word)
A (top of screen )
M (middle of screen)
$ (end of line)
Screen movement :
#!/bin/bash
echo "Hello, World!"
OUTPUT:
2. Simple Calculator
Create a script that takes two numbers as input and performs basic arithmetic operations (add,
subtract, multiply, divide)
#!/bin/bash
echo"Enter first number:"
read num1
echo"Enter second number:"
read num2
echo"Choose operation (+, -, *, /):"
read op
case$opin
+) echo"Result: $((num1 + num2))" ;;
-)echo"Result: $((num1 - num2))" ;;
*) echo"Invalid operator" ;;
esac
OUTPUT:
Write a script that checks if a number entered by the user is even or odd
#!/bin/bash
echo"Enter a number:"
read num
if ((num % 2 == 0)); then
echo"$num is Even"
else
echo"$num is Odd"
fi
OUTPUT:
#!/bin/bash
echo"Enter filename:"
read filename
if [ -e "$filename" ]; then
echo"File exists."
else
echo"File does not exist."
fi
OUTPUT
#!/bin/bash
for i in {1..10}; do
echo$i
done
OUTPUT:
Using if
#!/bin/bash
echo"Enter a number:"
read num
if [ $num -gt 0 ]; then
echo"The number is positive."
fi
OUTPUT:
#!/bin/bash
echo"Enter a number:"
read num
if [ $num -gt 0 ]; then
echo"The number is positive."
else
echo"The number is negative or zero."
fi
OUTPUT:
OUTPUT:
2. Loop Constructs:
1. for loop
#!/bin/bash
for i in {1..10}
do
echo "Number: $i"
done
OUTPUT:
2. while loop:
#!/bin/bash
i=1
while [$i -le 7 ]
do
echo "Number: $i"
((i++))
Done
OUTPUT:
3. Do while:
#!/bin/bash
# Mimicking the 'do-while' loop behavior in Shell
valid=false
# Using while loop to mimic the do-while loop
while [ "$valid" == false ]; do
echo "Please enter a positive number:”
read num
# Check if the number is positive
if [ "$num" -gt 0 ]; then
2. Remove a Directory
#!/bin/bash
Echo “enter directory name to remove:”
eead diname
rmdir “$dirname”
3. creating a file
SANKETIKA VIDYA PARISHAD ENGINEERING COLLEGE 26
DEPARTEMENT OF COMPUTER SCIENCE AND ENGINEERING
#!/bin/bash
echo “enter the file name to create:”
read filename
touch “$filename”
4. Writing to a file:
#!/bin/bash
echo “Enter the file name:”
read filename
echo “Enter the text to write to the file:”
read text
echo “$text” > “$filename”
echo “Content written to ‘$filename’.”
OUTPUT:
6. Deleting a file:
#!/bin/bash
echo “Enter the filename to delete:”
read filename
if[-f “$filename”]; then
rm “$filename”
echo “File ‘$filename’ has been deleted.”
else
echo “File ‘$filename’ does not exist.”
fi
Output:
2. System calls :
#include<stdio.h>
#include<unistd.h>
#include<sys/wait.h>
int main()
{
int pid = fork();
if(pid == 0) {
printf(“Child process\n”);
int main() {
FILE *file;
char data[] = "Hello this is a sample text for file operations in c.";
if (file == NULL) {
return 1;
fclose(file);
if (file == NULL) {
return 1;
char buffer[100];
buffer[sizeof(buffer) - 1] = '\0';
fclose(file);
return 0;
OUTPUT:
}
OUTPUT:-
1. Chaining:
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/wait.h>
int main() {
int pipe1[2], pipe2[2];
pid_t pid1, pid2, pid3;
}
close(pipe1[1]);
exit(0);
}
int num;
while (read(pipe1[0], &num, sizeof(int)) > 0) {
if (num % 2 == 0) {
write(pipe2[1], &num, sizeof(int));
}
}
close(pipe1[0]);
close(pipe2[1]);
exit(0);
}
int num;
while (read(pipe2[0], &num, sizeof(int)) > 0) {
printf("Even number: %d\n", num);
}
close(pipe2[0]);
exit(0);
}
return 0;
}
Output:
2. Spawing:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>
int main() {
pid_t pid;
if (pid == -1) {
// If fork fails
perror("fork failed");
exit(1);
}
if (pid == 0) {
// Child process code
printf("Child process: Executing 'ls' command\n");
// If execlp fails
perror("execlp failed");
exit(1);
} else {
// Parent process code
printf("Parent process: Waiting for child to finish...\n");
return 0;
}
Output:
Output:
int main() {
int pipefd[2];
pid_t pid;
if (pipe(pipefd) == -1) {
perror("pipe failed");
return 1;
}
pid = fork();
if (pid < 0) {
perror("fork failed");
return 1;
}
if (pid > 0) {
// Parent process: runs "ls"
close(pipefd[0]); // Close unused read end
dup2(pipefd[1], STDOUT_FILENO); // Redirect stdout to pipe write end
close(pipefd[1]);
return 0;
}
OUTPUT:
MODULE 2
1. C PROGRAMS TO STUDY PROCESS SCHEDULING
IMPLEMENTING FCFS,SHORTEST JOB FIRST, AND ROUND ROBIN
ALGORITHMS:
1. FCFS: (program-1):
#include<stdio.h>
int main()
{
int AT[10],BT[10],WT[10],TT[10],n;
int burst=0,cmpl_T;
float Avg_WT,Avg_TT,Total=0;
printf("Enter number of the process\n");
scanf("%d",&n);
printf("Enter Arrival time and Burst time of the process\n");
printf("AT\tBT\n");
for(int i=0;i<n;i++)
{
scanf("%d%d",&AT[i],&BT[i]);
}
// Logic for calculating Waiting time
for(int i=0;i<n;i++)
{
if(i==0)
WT[i]=AT[i];
else
WT[i]=burst-AT[i];
burst+=BT[i];
Total+=WT[i];
}
Avg_WT=Total/n;
// Logic for calculating Turn around time
cmpl_T=0;
Total=0;
for(int i=0;i<n;i++)
{
cmpl_T+=BT[i];
TT[i]=cmpl_T-AT[i];
Total+=TT[i];
}
Avg_TT=Total/n;
// printing of outputs
printf("Process ,Waiting_time ,TurnA_time\n");
for(int i=0;i<n;i++)
{
printf("%d\t\t%d\t\t%d\n",i+1,WT[i],TT[i]);
}
printf("Average waiting time is : %f\n",Avg_WT);
printf("Average turn around time is : %f\n",Avg_TT);
return 0;
}
OUTPUT:
2. SJF: (program-2):
#include<stdio.h>
#include<string.h>
void main()
{
int et[20],at[10],n,i,j,temp,st[10],ft[10],wt[10],ta[10];
int totwt=0,totta=0;
float awt,ata;
char pn[10][10],t[10];
//clrscr();
printf("Enter the number of process:");
scanf("%d",&n);
for(i=0; i<n; i++)
{
printf("Enter process name, arrival time& execution time:");
//flushall();
scanf("%s%d%d",pn[i],&at[i],&et[i]);
}
for(i=0; i<n; i++)
for(j=0; j<n; j++)
{
if(et[i]<et[j])
{
temp=at[i];
at[i]=at[j];
at[j]=temp;
temp=et[i];
et[i]=et[j];
et[j]=temp;
strcpy(t,pn[i]);
strcpy(pn[i],pn[j]);
strcpy(pn[j],t);
}
}
for(i=0; i<n; i++)
{
if(i==0)
st[i]=at[i];
else
st[i]=ft[i-1];
wt[i]=st[i]-at[i];
ft[i]=st[i]+et[i];
ta[i]=ft[i]-at[i];
totwt+=wt[i];
totta+=ta[i];
}
awt=(float)totwt/n;
ata=(float)totta/n;
printf("\nPname\tarrivaltime\texecutiontime\twaitingtime\ttatime");
for(i=0; i<n; i++)
printf("\n%s\t%5d\t\t%5d\t\t%5d\t\t%5d",pn[i],at[i],et[i],wt[i],ta[i]);
printf("\nAverage waiting time is:%f",awt);
printf("\nAverage turnaroundtime is:%f",ata);
}
OUTPUT:
int wait_time=0,turnaround_time=0,at[10],bt[10],rt[10];
printf("Enter Total Process:\t ");
scanf("%d",&n);
remain=n;
for(count=0;count<n;count++)
{
printf("Enter Arrival Time and Burst Time for Process Process Number %d :",count+1);
scanf("%d",&at[count]);
scanf("%d",&bt[count]);
rt[count]=bt[count];
}
printf("Enter Time Quantum:\t");
scanf("%d",&time_quantum);
printf("\n\nProcess\t|Turnaround Time|Waiting Time\n\n");
for(time=0,count=0;remain!=0;)
{
if(rt[count]<=time_quantum && rt[count]>0)
{
time+=rt[count];
rt[count]=0;
flag=1;
}
else if(rt[count]>0)
{
rt[count]-=time_quantum;
time+=time_quantum;
}
if(rt[count]==0 && flag==1)
{
remain--;
printf("P[%d]\t|\t%d\t|\t%d\n",count+1,time-at[count],time-at[count]-bt[count]);
wait_time+=time-at[count]-bt[count];
turnaround_time+=time-at[count];
flag=0;
}
if(count==n-1)
count=0;
else if(at[count+1]<=time)
count++;
else
count=0;
}
printf("\nAverage Waiting Time= %f\n",wait_time*1.0/n);
printf("Avg Turnaround Time = %f",turnaround_time*1.0/n);
return 0;
}
OUTPUT:
pageFaults--;
}
}
pageFaults++;
if((pageFaults <= frames) && (s == 0))
{
temp[m] = referenceString[m];
}
else if(s == 0)
{
temp[(pageFaults - 1) % frames] = referenceString[m];
}
printf("\n");
for(n = 0; n < frames; n++)
{
printf("%d\t", temp[n]);
}
}
printf("\nTotal Page Faults:\t%d\n", pageFaults);
return 0;
}
OUTPUT:
flag1 = flag2 = 1;
break;
}
}
if(flag1 == 0){
for(j = 0; j < no_of_frames; ++j){
if(frames[j] == -1){
faults++;
frames[j] = pages[i];
flag2 = 1;
break;
}
}
}
if(flag2 == 0){
flag3 =0;
pos = j;
flag3 = 1;
break;
}
}
if(flag3 ==0){
max = temp[0];
pos = 0;
OUTPUT:
#define MAX_FRAMES 10
time[j] = i;
break;
}
}
} else {
// If page is not in memory, find the LRU page to replace
int lruIndex = findLRU(time, numFrames);
frames[lruIndex] = page;
time[lruIndex] = i;
pageFaults++;
}
int main() {
int numFrames, numPages;
int pageReferences[numPages];
return 0;
}
OUTPUT:
if (canProceed) {
for (int j = 0; j < R; j++) {
work[j] += allocation[p][j];
}
finish[p] = 1;
safeSeq[count++] = p;
found = 1;
break;
}
}
}
if (!found) {
return 0; // No safe sequence found, deadlock detected
}
}
return 1;
} else {
// Rollback
for (int i = 0; i < R; i++) {
available[i] += request[i];
allocation[pid][i] -= request[i];
need[pid][i] += request[i];
}
printf("Error: Request cannot be granted (would lead to deadlock).\n");
return 0;
}
}
int main() {
// Input Allocation Matrix
printf("Enter the Allocation matrix (5x3):\n");
for (int i = 0; i < P; i++) {
for (int j = 0; j < R; j++) {
scanf("%d", &allocation[i][j]);
}
}
return 0;
}
OUTPUT:
Int main() {
int m, n;
return 0;
}
Output:
2. BEST FIT:
#include <stdio.h>
Int main()
{
Int a[20], b[20], c[20], b1, c1;
Int i, j, temp;
Static int barr[20], carr[20];
Printf("\n\t\t\tmemory management"" scheme - best fit");
Printf("\nenter the number of ""blocks:");
Scanf("%d", &b1);
Printf("enter the number of"" processes:");
Scanf("%d", &c1);
Int lowest = 9999;
Printf("\nenter the size of the"" blocks:\n");
For (i = 1; i <= b1; i++)
{
Printf("block no.%d:", i);
Scanf("%d", &b[i]);
}
Printf("\nenter the size of"" the processes :\n");
3. WORST FIT:
#include <stdio.h>
#define max 10
// function to find the largest free block
Int worstfit(int blocksize[], int m, int processsize[], int n) {
// stores the result (the allocation status of processes)
Int allocation[n];
// initialize all processes as not allocated
For (int i = 0; i < n; i++) {
Allocation[i] = -1;
}
Return 0;
}
Int main() {
// size of memory blocks
Int blocksize[max] = {100, 500, 200, 300, 600};
// size of processes
Int processsize[max] = {212, 417, 112, 426};
Int m = sizeof(blocksize) / sizeof(blocksize[0]);
Int n = sizeof(processsize) / sizeof(processsize[0]);
// Divide requests into two lists: left and right of the start position
for (int i = 0; i < n; i++) {
if (requests[i] < start) {
left[left_index++] = requests[i];
} else {
right[right_index++] = requests[i];
}
// Function to implement SSTF (Shortest Seek Time First) Disk Scheduling Algorithm
void sstf(int requests[], int n, int start) {
int total_distance = 0;
int visited[MAX_CYLINDERS] = {0};
int count = 0;
int current_position = start;
// Divide requests into two lists: left and right of the start position
for (int i = 0; i < n; i++) {
if (requests[i] < start) {
left[left_index++] = requests[i];
} else {
right[right_index++] = requests[i];
}
}
int requests[n];
printf("Enter the disk requests: ");
for (int i = 0; i < n; i++) {
scanf("%d", &requests[i]);
}
printf("Enter the starting position of the disk head: ");
scanf("%d", &start);
printf("Enter the direction (1 for right, 0 for left): ");
scanf("%d", &direction);
// Call SCAN Disk Scheduling
scan(requests, n, start, direction);
// Call SSTF Disk Scheduling
sstf(requests, n, start);
VIVA QUESTIONS
1. The ls command is used to list the files and directories in the current working directory.
2. To create a new file in the Vi editor, type vi filename, and the editor will open a new file if
it doesn't already exist.
3. The chmod command is used to change the permissions of a file or directory in Unix.
5. To run a shell script, use the command ./scriptname.sh after giving it executable permissions
using chmod +x scriptname.sh.
6. The if statement allows the shell script to make decisions based on conditional expressions.
7. You can check if a file exists using the condition if [ -e filename ]; then in a shell script.
8. The for loop is used to repeat a set of commands for a specific number of times or over a list
of items.
9. Command-line arguments can be passed by using argc (argument count) and argv[]
(argument vector) in the main function: int main(int argc, char *argv[]).
10. The fork() system call is used to create a new process by duplicating the calling process.
11. The make utility automates the process of compiling and building projects by reading
instructions from a Make file.
SANKETIKA VIDYA PARISHAD ENGINEERING COLLEGE 76
DEPARTEMENT OF COMPUTER SCIENCE AND ENGINEERING
12. What is the difference between a parent process and a child process in C?
12. The parent process is the original process that calls fork(), and the child process is the new
process created by fork().
14. Process chaining refers to the sequence of creating multiple processes where one process
may create another, and so on.
16. The errno variable stores error codes set by system calls and library functions to indicate
the type of error that occurred.
17. The perror() function prints a descriptive error message to the standard error stream, based
on the value of errno.
18. The pipe() system call creates a unidirectional communication channel between two
processes for inter-process communication.
19. A pipe is created using pipe() and the file descriptors returned are used to read and write
between processes.
20. FCFS is a non-preemptive scheduling algorithm where the process that arrives first is
executed first.
21. How does the Shortest Job First (SJF) scheduling algorithm work?
21. SJF schedules the process with the shortest burst time first, aiming to minimize waiting
time.
22. Round Robin is a preemptive scheduling algorithm that assigns each process a fixed time
slice (quantum) in a circular order.
23. FIFO (First In, First Out) replaces the oldest page in memory when a page fault occurs.
24. How does the Least Recently Used (LRU) page replacement algorithm work?
24. LRU replaces the page that has not been used for the longest time when a page fault occurs.
25. The Optimal page replacement algorithm replaces the page that will not be used for the
longest time in the future.
26. Deadlock occurs when a set of processes is blocked because each process is holding a
resource and waiting for another resource held by another process.
28. The First Fit algorithm allocates the first available memory block that is large enough to
accommodate the requested process.
29. The Best Fit algorithm allocates the smallest available memory block that can
accommodate the process, aiming to minimize wasted space.
30. The Worst Fit algorithm allocates the largest available memory block to a process, aiming
to leave large contiguous free spaces.
31. SCAN moves the disk arm from one end to the other, servicing requests, and then reverses
direction when it reaches the end.
32. What is the SSTF (Shortest Seek Time First) disk scheduling algorithm?
32. SSTF selects the disk request that is closest to the current disk arm position.
33. LOOK is similar to SCAN, but instead of going to the end of the disk, it stops when there
are no more requests in the current direction.