Lab Manual
Lab Manual
Code:
Output:
Read name
echo "Your First Name: $name"
read Lname
echo "Your Last Name: $Lname"
read gender
echo "Your Gender: $gender"
read number
echo "Phone No: $number"
read cnic
echo "CNIC: $cnic"
read address
echo "Address: $address"
Lab: 02
$0 echo "FileName:
$0"
$n echo"Name : $1"
echo "LastName :
$2"
$# echo
“TotalArgument:
$#”
$* echo “ $*”
$@ echo “ $@”
$? echo “ $?”
$$ echo “ $$”
$! echo “ $!”
Lab: 03
- : make a="5"
decrement b="6"
operator
val=`expr $a - $b`
echo "$val"
* : Mutiply a="5"
negative and b="6"
positive number
echo "answer=$
((a*b))"
then
echo $a is lower
than $b
else
echo $b is lower
than $a
fi
Greater than: a="20"
Compare two b="4"
value
if [ $a -gt $b ]
then
echo $a is greater
than $b
else
echo $b is greater
than $a
fi
EquUniversityty a="20"
: Compare two b="20"
value
if [ $a -eq $b ]
then
echo $a is equal $b
else
echo $b is unequal
$a
fi
then
echo $a is equal $b
else
echo $b is unequal
$a
fi
Lab: 04
Code:
Code:
2.
Code:
Code:
3.
Codet:
Code:
Code:
Code:
5.
Code:
Code:
Lab: 05
INPU OUTPU
T T
Variable Substitution
Form Description
${var:+word} If var is set, word is substituted for var. The value of vardoes not
change.
INPUT
OUTPUT
Quoting mechanisms
Quoting Description
Single quote All special characters between these quotes lose their special meaning.
Double quote Most special characters between these quotes lose their special
meaning with these exceptions:
● $
● `
● \$
● \'
● \"
● \\
Backslash Any character immediately following the backslash loses its special
meaning.
Back Quote Anything in between back quotes would be treated as a command and
would be executed.
INPUT
OUTPUT
I/O Redirection
Output Redirection
Input Redirection
Man Page Section
Lab: 06
Listing Files
Hidden Files
Meta Characters
Creating Files
Copying Files
Renaming Files
Deleting Files
Lab: 07
Home Directory
Absolute/Relative Pathnames
Listing Directories
Creating Directories
Creating Parent Directories
Changing Directories
Changing Permissions
Chmod o+wx filename
Chmod u-x
Changing Ownership
Lab: 09
TASK 1:
DESCRIPTION
Assume all the processes arrive at the same time.
#include<conio.h>
int main()
{
printf("\nEnter Burst Time for Process %d -- ", i); scanf_s("%d", &bt[i]);
OUTPUT
#include<conio.h>
int main()
{p[i] = i;
temp = bt[i];
bt[i] = bt[k];
bt[k] = temp;
temp = p[i];
p[i] = p[k];
p[k] = temp;
printf("\n\t P%d \t\t %d \t\t %d \t\t %d", p[i], bt[i], wt[i], tat[i]);
_getch();
Output:
#include<conio.h>
int main()
{int i, j, n, bu[10], wa[10], tat[10], t, ct[10], max; float awt = 0, att = 0, temp = 0;
max = bu[0];
max = bu[i];
if (bu[i] != 0)
bu[i] = 0;
}else
awt += wa[i];}
_getch();}
Output:
Priority CPU SCHEDULING ALGORITHM
Code:
#include<stdio.h>
#include<conio.h>
int main()
{int p[20], bt[20], pri[20], wt[20], tat[20], i, k, n, temp; float wtavg, tatavg;
p[i] = i;
printf("Enter the Burst Time & Priority of Process %d --- ", i);
scanf_s("%d %d", &bt[i], &pri[i]);
temp = p[i];
p[i] = p[k];
p[k] = temp;
temp = bt[i];
bt[i] = bt[k];
bt[k] = temp;
temp = pri[i];
pri[i] = pri[k];
pri[k] = temp;
printf("\n%d \t\t %d \t\t %d \t\t %d \t\t %d ", p[i], pri[i], bt[i], wt[i], tat[i]);
_getch();}
Output:
TASK2:
DESCRIPTION
Multi-level queue scheduling algorithm is used in scenarios where the processes can be
classified into groups based on property like process type, CPU time, IO access,
memory size, etc. In a multi-level queue scheduling algorithm, there will be 'n' number of
queues, where 'n' is the number of groups the processes are classified into. Each queue
will be assigned a priority and will have its own scheduling algorithm like round-
robin scheduling or FCFS. For the process in a queue to execute, all the queues of
priority higher than it should be empty, meaning the process in those high priority
queues should have completed its execution. In this scheduling algorithm, once
assigned to a queue, the process will not move to any other queues.
Code:
#include<stdio.h>
#include<conio.h>
int main()
int p[20], bt[20], su[20], wt[20], tat[20], i, k, n, temp; float wtavg, tatavg;
p[i] = i;
temp = p[i];
p[i] = p[k];
p[k] = temp;
temp = bt[i];
bt[i] = bt[k];
bt[k] = temp;
temp = su[i];
su[i] = su[k];
su[k] = temp;
{
wt[i] = wt[i - 1] + bt[i - 1];tat[i] = tat[i - 1] + bt[i];
printf("\n%d \t\t %d \t\t %d \t\t %d \t\t %d ", p[i], su[i], bt[i], wt[i],
tat[i]);
_getch();
Output:
Lab: 10
TASK1
DESCRIPTION
A file is a collection of data, usually stored on disk. As a logical entity, a file enables to divide
data into meaningful groups. As a physical entity, a file should be considered in terms of its
organization. The term "file organization" refers to the way in which data is stored in a file and,
consequently, the method(s) by which it can be accessed.
#include<conio.h>
struct fileTable
}ft[30];
void main()
scanf_s("%d", &n);
scanf_s("%s", ft[i].name);
scanf_s("%d", &ft[i].sb);
scanf_s("%d", &ft[i].nob);
scanf("%s", s);
break;
if (i == n)
else
_getch();}
Output:
#include<conio.h>
struct fileTable
char name[20];
int nob;
}ft[30];
struct block
int bno;
};
void main()
int i, j, n;
char s[20];
scanf_s("%d", &n);
scanf_s("%s", ft[i].name);
scanf_s("%d", &ft[i].nob);
temp = ft[i].sb;
scanf_s("%d", &temp->bno);
temp->next = NULL;
scanf_s("%s", s);
for (i = 0;i < n;i++)
if (i == n)
else
_getch();
Output:
#include<conio.h>
struct fileTable
{
char name[20];
}ft[30];
void main()
printf("\nEnter the blocks of the file :"); for (j = 0;j < ft[i].nob;j++)
scanf_s("%d", &ft[i].blocks[j]);
if (strcmp(s, ft[i].name) == 0)
if (i == n)
else
_getch();
Output:
Lab: 11
TASK1:
DESCRIPTION
MFT (Multiprogramming with a Fixed number of Tasks) is one of the old memory
management techniques in which the memory is partitioned into fixed size partitions and
each job is assigned to a partition. The memory assigned to a partition does not
change. MVT (Multiprogramming with a Variable number of Tasks) is the memory
management technique in which each job gets just the amount of memory it needs.
That is, the partitioning of memory is dynamic and changes as jobs enter and leave the
system. MVT is a more ``efficient'' user of resources. MFT suffers with the problem of
internal fragmentation and MVT suffers with external fragmentation.
PROGRAM
#include<conio.h>
int main()
printf("Enter the total memory available (in Bytes) -- "); scanf_s("%d", &ms);
printf("\t\tNO\t\t---");
else
p++;
if (i < n)
Output:
MVT MEMORY MANAGEMENT TECHNIQUE
Code:
#include<stdio.h>
#include<conio.h>
int main()
printf("\nEnter the total memory available (in Bytes)-- "); scanf_s("%d", &ms);
temp = ms;
else
printf("\nMemory is Full");
break;
_getch();
Output:
TASK2:
DESCRIPTION
One of the simplest methods for memory allocation is to divide memory into
several fixed-sized partitions. Each partition may contain exactly one process. In
this multiple-partition method, when a partition is free, a process is selected from the
input queue and is loaded into the free partition. When the process terminates, the
partition becomes available for another process. The operating system keeps a table
indicating which parts of memory are available and which are occupied. Finally, when a
process arrives and needs memory, a memory section large enough for this process is
provided. When it is time to load or swap a process into main memory, and if there is
more than one free block of memory of sufficient size, then the operating system must
decide which free block to allocate. Best-fit strategy chooses the block that is closest in
size to the request. First-fit chooses the first available block that is large enough. Worst-
fit chooses the largest available block.
PROGRAM
FIRST-FIT
Code:
#include<stdio.h>
#include<conio.h>
#define max 25
void main()
int frag[max], b[max], f[max], i, j, nb, nf, temp; static int bf[max], ff[max];
if (bf[j] != 1)
ff[i] = j;
break;
}
}
frag[i] = temp;
bf[ff[i]] = 1;
_getch();
Output:
BEST-FIT
Code:
#include<stdio.h>
#include<conio.h>
#define max 25
void main()
if (bf[j] != 1)
ff[i] = j;
lowest = temp;
frag[i] = lowest;
bf[ff[i]] = 1;
lowest = 10000;
}
printf("\nFile No\tFile Size \tBlock No\tBlock Size\tFragment"); for (i = 1;i <=
nf && ff[i] != 0;i++)
_getch();
Output:
WORST FIT
Code:
#include<stdio.h>
#include<conio.h>
#define max 25
void main()
int frag[max], b[max], f[max], i, j, nb, nf, temp, highest = 0; static int
bf[max], ff[max];
ff[i] = j;
highest = temp;
}
frag[i] = highest;
bf[ff[i]] = 1;
highest = 0;
_getch();
Output:
Lab: 12
Objective:
Write a C program to simulate the pagging memory management
techniques.
TASK:
DESCRIPTION
In computer operating systems, paging is one of the memory management schemes by
which a computer stores and retrieves data from the secondary storage for use in main
memory. In the paging memory-managementscheme, the operating system retrieves
data from secondary storage in same-size blocks called pages. Paging is a memory-
management scheme that permits the physical address space a process to be
noncontiguous. The basic method for implementing paging involves breaking physical
memory into fixed-sized blocks called frames and breaking logical memory into blocks
of the same size called pages. When a process is to be executed, its pages are loaded
into any available memory frames from their source.
PROGRAM
#include<stdio.h>
#include<conio.h>
int main()
int ms, ps, nop, np, rempages, i, j, x, y, pa, offset; int s[10], fno[10][20];
nop = ms / ps;
rempages = nop;
printf("\nEnter pagetable for p[%d] --- ", i); for (j = 0;j < s[i];j++)
scanf_s("%d", &fno[i][j]);
pa = fno[x][y] * ps + offset;
_getch();
Output:
Lab: 13
Deadlock Management Techniques
Objective:
Write a C program to simulate Bankers algorithm for the purpose of
deadlock avoidance.
● SCAN
● C-SCAN
TASK1:
DESCRIPTION
In a multiprogramming environment, several processes may compete for a finite number
of resources. A process requests resources; if the resources are not available at that
time, the process enters a waiting state. Sometimes, a waiting process is never again
able to change state, because the resources it has requested are held by other waiting
processes. This situation is called a deadlock. Deadlock avoidance is one of the
techniques for handling deadlocks. This approach requires that the operating system be
given in advance additional information concerning which resources a process will
request and use during its lifetime. With this additional knowledge, it can decide for
each request whether or not the process should wait. To decide whether the current
request can be satisfied or must be delayed, the system must consider the resources
currently available, the resources currently allocated to each process, and the future
requests and releases of each process.
Banker’s algorithm is a deadlock avoidance algorithm that is applicable to a system with
multiple instances of each resource type.
PROGRAM
Code:
#include<stdio.h>
#include<conio.h>
struct file
{
int all[10]; int max[10]; int need[10]; int flag;
};
void main()
{
struct file f[10]; int fl;
int i, j, k, p, b, n, r, g, cnt = 0, id, newr; int avail[10], seq[10];
printf("Enter number of processes -- "); scanf_s("%d", &n);
printf("Enter number of resources -- "); scanf_s("%d", &r);
for (i = 0;i < n;i++)
{
printf("Enter details for P%d", i); printf("\nEnter allocation\t -- \t");
for (j = 0;j < r;j++)
scanf_s("%d", &f[i].all[j]); printf("Enter Max\t\t -- \t"); for (j =
0;j < r;j++)
scanf_s("%d", &f[i].max[j]);
f[i].flag = 0;
}
printf("\nEnter Available Resources\t -- \t"); for (i = 0;i < r;i++)
scanf_s("%d", &avail[i]);
printf("\nEnter New Request Details -- "); printf("\nEnter pid \t -- \t");
scanf_s("%d", &id);
printf("Enter Request for Resources \t -- \t"); for (i = 0;i < r;i++)
{
scanf_s("%d", &newr); f[id].all[i] += newr;
avail[i] = avail[i] - newr;
}
for (i = 0;i < n;i++)
{
for (j = 0;j < r;j++)
{
f[i].need[j] = f[i].max[j] - f[i].all[j];if (f[i].need[j] < 0)
f[i].need[j] = 0;
}
}
cnt = 0;
fl = 0;
while (cnt != n)
{
g = 0;
for (j = 0;j < n;j++)
{
if (f[j].flag == 0)
{
b = 0;
for (p = 0;p < r;p++)
{
if (avail[p] >= f[j].need[p])
b = b + 1;
else
b = b - 1;
}
if (b == r)
{
printf("\nP%d is visited", j); seq[fl++] = j;
f[j].flag = 1;
for (k = 0;k < r;k++)
avail[k] = avail[k] + f[j].all[k];
cnt = cnt + 1;
printf("(");
for (k = 0;k < r;k++)
printf("%3d", avail[k]);
printf(")");
g = 1;
}
}
}
if (g == 0)
{printf("\n REQUEST NOT GRANTED -- DEADLOCK OCCURRED"); printf("\n SYSTEM
IS IN UNSAFE STATE");
goto y;}}
printf("\nSYSTEM IS IN SAFE STATE"); printf("\nThe Safe Sequence is -- ("); for (i
= 0;i < fl;i++)
printf("P%d ", seq[i]); printf(")");
y:printf("\nProcess\t\tAllocation\t\tMax\t\t\tNeed\n");
for (i = 0;i < n;i++)
{printf("P%d\t", i);
for (j = 0;j < r;j++)
printf("%6d", f[i].all[j]);
for (j = 0;j < r;j++)
printf("%6d", f[i].max[j]);
for (j = 0;j < r;j++)
printf("%6d", f[i].need[j]);
printf("\n");
}
_getch();
}
Output: