0% found this document useful (0 votes)
30 views

Osy Practical Output

practical output

Uploaded by

sanskrutinile06
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views

Osy Practical Output

practical output

Uploaded by

sanskrutinile06
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

Practical1

Practical 2
Practical 3

Practical 4

5
Practical 6
Practical 7
Practical 8
Practical 10

Single decision :
echo "Enter percentage here :"
read grade
if [ $grade -ge 90 ] && [ $grade -le 100 ]
then
echo "Grade A"
fi
if [ $grade -ge 70 ] && [ $grade -lt 90 ]
then
echo "Grade B"
fi
if [ $grade -ge 50 ] && [ $grade -lt 70 ]
then
echo "Grade C"
fi
if [ $grade -ge 35 ] && [ $grade -lt 50 ]
then
echo "Grade D"
fi
if [ $grade -lt 35 ]
then
echo "FAIL"
fi
Double decision
echo "Enter percentage of Student : "
read grade
if [ $grade -gt 40 ]
then
echo "Pass"
else
echo "Fail"
fi

Multiple decision
echo "Enter percentage of Student : "
read grade
if [ $grade -ge 90 ]
then
echo "Grade A"
elif [ $grade -ge 80 ]
then
echo "Grade b"
elif [ $grade -ge 70 ]
then
echo "Grade c"
elif [ $grade -ge 60 ]
then
echo "Grade d"
elif [ $grade -ge 40 ]
then
echo "Grade e"
else
echo "Grade Fail"
fi

Nested if
read -p 'username :' username
if [ "$username" == "abc" ]
then
read -p 'password :' password
if [ "$password" == "pwd" ]
then
echo "Login Successfully"
else
echo "Wrong Password"
fi
else
echo "Wrong Username"
fi
Finding greatest number
echo "Enter number1 number : "
read n1
echo "Enter number2 number : "
read n2
echo "Enter number3 number : "
read n3
if [ $n1 -gt $n2 ] && [ $n1 -gt $n3 ]
then
echo "$n1 is Greater"
elif [ $n2 -gt $n3 ]
then
echo "$n2 is Greater"
else
echo "$n3 is Greater"
fi

Practical 11

Fibonacci series
read -p 'Enter no for fibonacci = ' no
x=0
y=1
no1=$no
while [ $no -gt 0 ]
do
z=$(( x + y ))
#echo $z
x=$y
y=$z
no=$(( no - 1 ))
done
echo "Fibonacci of $no1 is $y"

Five digit number addition


read -n 5 -p 'Enter 5 digit number: ' no
sum1=0
while [ $no -gt 0 ]
do
i=$(( no % 10 ))
sum1=$(( sum1 + i ))
no=$(( no / 10 ))
done
echo " Sum = $sum1"

Loop to print days in week


for i in sun mon tue wed thur fri sat
do
echo $i
done

Print * pattern

read -p "enter 1st no" no1


read -p "enter 2nd no" no2
echo -e "1 add \n2 subtract \n3 multiply \n4 divide"
read -p "enter your choice " ch
case $ch in
1) c=$(( $no1 + $no2 ))
echo "addition = $c ";;
2) c=$(( $no1 - $no2 ))
echo "subtraction = $c ";;
3) c=$(( $no1 * $no2 ))
echo "multiplication = $c ";;
4) c=$(( $no1 / $no2 ))
echo "division = $c ";;
*) echo "invalid choice";;
esac

Case statement for mathematical operation

read -p 'Enter no for pattern = ' no


i=1
j=1
while [ $i -le $no ]
do
while [ $j -le $no ]
do
if [ $i -le $j ]
then
echo -n "* "
fi
j=$(( j + 1 ))
done
j=1
i=$(( i + 1 ))
echo ""
done

Practical 12
Shell script to copy program one file to another
echo "Enter File name to copy \c"
read f1
echo "Enter file name \c"
read f2
if [ -f $f1 ]
then
cp $f1 $f2
else
echo "$f1 does not exist"
fi

Shell script to display all directories


echo "**Following are the directories of current directories**"
cd
ls -l |grep ^d

Shell script to list all files in directory


echo "Enter directory name"
read dir
if [ -d $dir ]
then
echo "list of files in the directory"
cd $dir
ls
else
echo "Enter proper directory name"
fi

Case statement
echo "enter file name"
read file
if [ -d "$file" ]
then
echo "it is directory"
else
echo "Enter your choice"
echo "1.copy file "
echo "2.rename file"
echo "3.remove"
read ch
case "$ch" in
"1") echo "Enter file name to be copied"
read cpfile
cp $file $cpfile
echo "File copied"
;;
"2") echo "enter name to rename "
read newname
mv $file $newname
echo "$file renamed as $newname"
;;
"3") rm $file
echo "removed "
;;
esac
fi

Shell script to check it is file or directory


echo "Enter file or directory name"
read file
if [ -f "$file" ]
then
echo "$file It is a file"
else
if [ -d "$file" ]
then
echo "$file It is a directory"
fi
fi

Practical 13

Shell script to check file permissions

echo Enter the File :


read line
if [ -r $line ]
then
echo $line has all the read permissions6
fi
if [ -x $line ]
then
echo $line has all the execute permissions6
fi
if [ -w $line ]
then
echo $line has all the write permissions6
fi

Shell script to list executable file

pwd
ls > f
exec < f
while read line
do
if [ -f $line ]
then
if [ -x $line ]
then
echo $line
fi
fi
done

Shell script to display all files with their permission

pwd
ls > f
exec < f
while read line
do
if [ -f $line ]
then
if [ -r "$line" ] && [ -w "$line" ] && [ -x "$line" ]
then
echo $line has all the permissions
fi
fi
done

Shell script to assign permission

echo "ENTER THE FILE:"


read -r file
if [ -e "$file" ]; then
chmod u+xrw "$file"
chmod g+xrw "$file"
chmod o+xrw "$file"
echo "Permissions have been set for $file"
else
echo "File does not exist."
fi

Practical 14

#include <stdio.h>
#include <conio.h>
int main() {
int n, bt[20], wt[20], tat[20], avwt = 0, avtat = 0, i, j;
printf("\nEnter Total Number of Processes (maximum 20): ");
scanf("%d", &n);
printf("\nEnter process burst times:\n");
for(i = 0; i < n; i++) {
printf("\nP[%d]: ", i + 1);
scanf("%d", &bt[i]);}
wt[0] = 0;
for(i = 1; i < n; i++) {
wt[i] = 0;
for(j = 0; j < i; j++)
wt[i] += bt[j];}
printf("\nProcess\t\tBurst Time\tWaiting Time\tTurnaround Time:\n");
for(i = 0; i < n; i++) {
tat[i] = bt[i] + wt[i];
avwt += wt[i];
avtat += tat[i];
printf("\nP[%d]\t\t%d\t\t%d\t\t%d", i + 1, bt[i], wt[i], tat[i]);
}
avwt /= i;
avtat /= i;
printf("\n\nAverage Waiting Time: %d", avwt);
printf("\nAverage Turnaround Time: %d", avtat);
return 0;
}
Practical 15

#include <stdio.h>
int main() {
int i, j, n, a[50], frame[10], no, k, Flag, count = 0;
printf("\nENTER THE NUMBER OF PAGES:\n");
scanf("%d", &n);
printf("\nENTER THE PAGE NUMBERS:\n");
for(i = 0; i < n; i++)
scanf("%d", &a[i]);
printf("\nENTER THE NUMBER OF FRAMES:\n");
scanf("%d", &no);
for(i = 0; i < no; i++)
frame[i] = -1;
j = 0;
printf("\n\tReference String\tPage Frames\n");
for(i = 0; i < n; i++) {
printf("%d\t\t", a[i]);
Flag = 0
for(k = 0; k < no; k++) {
if(frame[k] == a[i]) {
Flag = 1;
break;
}
}
if (Flag == 0) {
frame[j] = a[i];
j = (j + 1) % no;
count++;
for(k = 0; k < no; k++)
printf("%d\t", frame[k]);
printf("Page Fault: %d\n", count);
} else {
for(k = 0; k < no; k++)
printf("%d\t", frame[k]);
printf("Page Hit\n");
}
}
printf("\nTotal Page Faults: %d\n", count);
return 0;
}

Practical 9

Create command

You might also like