OS Record
OS Record
OS Record
}ft[30];
int main()
{
int i, j, n; char s[20];
printf("Enter no of files :");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\nEnter file name %d:",i+1);
scanf("%s",ft[i].name);
printf("Enter starting block of file %d :",i+1);
scanf("%d",&ft[i].sb);
printf("Enter no of blocks in file %d :",i+1);
scanf("%d",&ft[i].nob);
}
printf("\nEnter the file name to be searched - ");
scanf("%s",s);
for(i=0;i<n;i++)
if(strcmp(s, ft[i].name)==0)
break;
if(i==n)
printf("\nFile Not Found");
else
{
printf("\nFILE NAME START BLOCK NO OF BLOCKS BLOCKS
OCCUPIED\n"); printf("\n%s\t\t%d\t\t%d\t",ft[i].name,ft[i].sb,ft[i].nob);
for(j=0;j<ft[i].nob;j++)
printf("%d, ",ft[i].sb+j);
}
}
INPUT:
Enter no of files :3
Enter file name 1 :A
Enter starting block of file 1 :85
Enter no of blocks in file 1 :6
Enter file name 2 :B
Enter starting block of file 2 :102
Enter no of blocks in file 2 :4
Enter file name 3 :C
Enter starting block of file 3 :60
Enter no of blocks in file 3 :4
Enter the file name to be searched -- B
OUTPUT:
#include<stdio.h>
struct file
{
char fname[10];
int start,size,block[10];
}f[10];
int main()
{
int i,j,n;
printf("Enter no. of files:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter file name:");
scanf("%s",&f[i].fname);
printf("Enter starting block:");
scanf("%d",&f[i].start);
f[i].block[0]=f[i].start;
printf("Enter no.of blocks:");
scanf("%d",&f[i].size);
printf("Enter block numbers:");
for(j=1;j<=f[i].size;j++)
{
scanf("%d",&f[i].block[j])
printf("File\tstart\tsize\tblock\n");
for(i=0;i<n;i++)
{
printf("%s\t%d\t%d\t",f[i].fname,f[i].start,f[i].size);
for(j=1;j<=f[i].size-1;j++)
printf("%d--->",f[i].block[j]);
printf("%d",f[i].block[j]);
printf("\n");
OUTPUT:
12 15 45 32 25
abc 20 6 4--->12--->15--->45--->32--->25
x
yz 12 5 6--->5--->4--->3--->2
C) INDEXED FILE ALLOCATION
#include<stdio.h>
int main()
{
int n,m[20],i,j,sb[20],s[20],b[20][20],x;
1 3 3
2 2 2
Index is:2
A shell script is a computer program designed to be run by the Unix/Linux shell which could be
one of the following:
A shell is a command-line interpreter and typical operations performed by shell scripts include
file manipulation, program execution, and printing text. A Shell provides you with an interface
to the Unix system. It gathers input from you and executes programs based on that input. When
a program finishes executing, it displays that program's output. Shell script will have comments,
preceded by #
Operators in UNIX:
Operator Description
Checks if the value of two operands are equal or not; if yes, then the
-eq
condition becomes true.
Checks if the value of two operands are equal or not; if values are not
-ne
equal, then the condition becomes true.
Checks if the value of left operand is greater than the value of right
-gt
operand; if yes, then the condition becomes true.
Checks if the value of left operand is less than the value of right
-lt
operand; if yes, then the condition becomes true.
Checks if the value of left operand is less than or equal to the value
-le
of right operand; if yes, then the condition becomes true.
1. Shell script to perform arithmetic operations
# !/bin/bash
read fno
read sno
OUTPUT
sh read.sh
read n
rem=$(( $n % 2 ))
then
else
fi
Output
sh filename.sh
Enter a number: 20
No. is even
sh filename.sh
Enter a number: 9
No is odd
read num
fact=1
do
num=’expr $num – 1’
done
Output
sh fact.sh
enter a number: 4
Factorial of 4 is 24
4. Unix Shell Program to check whether the given Year is Leap year or not.
enter the year
read y
a=`expr $y % 4`
b=`expr $y % 100`
c=`expr $y % 400`
if [ $a -eq 0 -a $b -ne 0 -o $c -eq 0 ]
then
echo $y is leap year
else
echo $y is not leap year
fi
OutPut
2010
2010 is not leap year
5. To write a shell script program to find the biggest among given two numbers
echo "Enter the first number\n”
read a
echo "Enter the second number\n "
read b
if [$a –gt $b]
echo “ $a is greater”
else
echo “$b is greater”
if
OUTPUT:
Enter the first number
3
Enter the second number
5
5 is greater