Sunday, 7 June 2020

GTU NEW OS PRACTICALS

Program- 2

Write a shell script to generate mark sheet of a student. Take 3 subjects, calculate and display total marks, percentage and Class obtained by the student.

echo "Enter Subject-1 marks: "
read s1
echo "Enter Subject-2 marks: "
read s2
echo "Enter Subject-3 marks: "
read s3
total=$(( $s1 + $s2 + $s3 ))
echo "Total Marks : $total"
per=$(( $total / 3 ))
echo "Percentage: $per %"
if [ $per -gt 70 ]
then
echo "Distiction Class"
elif [ $per -ge 61 -a $per -le 70 ]
then
echo "First Class"
elif [ $per -ge 51 -a $per -le 60 ]
then
echo "Second Class"
elif [ $per -ge 41 -a $per -le 50 ]
then
echo "Third Class"
else
echo "Fail"
fi

Program- 3

Write a Shell Script to display the multiplication table of the given number.

echo "Enter a Number"
read n
i=1
while [ $i -le 10 ]
do
echo " $n x $i = `expr $n \* $i`"
i=`expr $i + 1`
done

Program- 4

Write a Shell Script to find factorial of given number n.

echo "Enter number"
read num
fact=1
while [ $num -gt 1 ]
do
 fact=$((fact * num)) #fact = fact * num
 num=$((num - 1)) #num = num - 1
done
echo $fact

Program- 5

Write a Shell Script in which will accept a number n and display first m prime numbers as output?

echo "enter start no="
read i
echo "enter end no="
read j
flag=0
tem=2
count=1
while [ $i -ne $j ]
do
 temp=`echo $i`
 while [ $temp -ne $tem ]
 do
 temp=`expr $temp - 1`
 n=`expr $i % $temp`
 if [ $n -eq 0 -a $flag -eq 0 ]
 then
 flag=1
 fi
 done
 if [ $flag -eq 0 ]
 then
 echo " prime No $count = $i"
 count=`expr $count + 1`
 else
 flag=0
 fi
 i=`expr $i + 1`
if [ $count -eq 11 ]
 then
 break
 fi
done

Program- 6

Write a Shell Script to find first n Fibonacci numbers like: 0 1, 1, 2, 3, 5, 13

echo "Enter Range"
read number
n1=1
n2=1
echo "Fibonacci Series:-"
for (( i = 0; $i < $number; i++ )); do
echo $n2
temp=$n1
n1=`expr $n1 + $n2`
n2=$temp
done

Program- 7

Write a Shell Script which will print the following menu and execute the given task?
a) Display calendar of current month
b) Display today s date and time
c) Display usernames that are currently logged in the system
d) Display your name at given x, y position
e) Display your terminal number

echo "1. Display calendar of current month"
echo "2. Display today's date and time"
echo "3. Display usernames that are currently logged in the system"
echo "4. Display your name at given x, y position"
echo "5. Display your terminal number"
echo "Enter choice:"
read choice
case $choice in
 1)
 echo $(cal)
 ;;
 2)
 echo $(date)
 ;;
 3)
 echo $(whoami)
 ;;
 4)
 printf "%20s%30s\n" Study Material
 ;;
 5)
 echo $(tty)
 ;;
esac

Program- 8

Write a Shell Script to read n numbers as command arguments and sort them in descending order.

echo "Enter N"
read n
for (( i = 1; i <= n; i++ )); do
echo "Enter Array ["$i"] : "
read array[i]
done
for (( i = 1; i <= 5; i++ )); do
for (( j = i+1; j <= 5; j++ )); do
if [[ ${array[i]} > ${array[j]} ]]; then
temp=${array[i]}
array[i]=${array[j]}
array[j]=$temp
fi
done
done
echo "Elements of sorted array:-"
for (( i = 1; i <= 5; i++ )); do
echo ${array[i]}
done

Program- 9

Write a Shell Script to display all executable files, directories and zero sized files from current directory.

#display empty file

find /home/student/Documents/ -type f -empty

#display directory
$ ls -d */

#display executable file
find /home/student/.anaconda/navigator/ -executable -type f

Program- 10

Write a Shell Script to check whether the given string is palindrome or not.

echo "Enter String"
read String
size=`expr length "$String"`
msg="Palindrome"
for (( i = 0, j = size-1; i < size; i++,j-- )); do
if [[ ${String:i:1} != ${String:j:1} ]]; then
msg="Not Palindrome"
fi
done
echo "String is $msg"

Program- 13

Write a Shell Script to validate the entered date. (E.g. Date format is: dd-mm- yyyy). 

# store day, month and year
dd=0
mm=0
yy=0

# store number of days in a month
days=0

# get day, month and year
echo -n "Enter day (dd) : "
read dd
echo -n "Enter month (mm) : "
read mm
echo -n "Enter year (yyyy) : "
read yy

# if month is negative (<0) or greater than 12
# then it is invalid month

if [ $mm -le 0 -o $mm -gt 12 ];
then
 echo "$mm is invalid month."
 exit 1
fi

# Find out number of days in given month
case $mm in
 1) days=31;;
 2) days=28 ;;
 3) days=31 ;;
 4) days=30 ;;
 5) days=31 ;;
 6) days=30 ;;
 7) days=31 ;;
 8) days=31 ;;
 9) days=30 ;;
 10) days=31 ;;
 11) days=30 ;;
 12) days=31 ;;
 *) days=-1;;
esac

# find out if it is a leap year or not
if [ $mm -eq 2 ]; # if it is feb month then only check of leap year
then
if [ $((yy % 4)) -ne 0 ] ; then
 : # not a leap year : means do nothing and use old value of days
elif [ $((yy % 400)) -eq 0 ] ; then
 # yes, it's a leap year
 days=29
elif [ $((yy % 100)) -eq 0 ] ; then
 : # not a leap year do nothing and use old value of days
else
 # it is a leap year
 days=29
fi
fi
# if day is negative (<0) and if day is more than
# that months days then day is invaild
if [ $dd -le 0 -o $dd -gt $days ];
then
 echo "$dd day is invalid"
 exit 3
fi
# if no error that means date dd/mm/yyyy is valid one
echo "$dd/$mm/$yy is a vaild date"

Program- 14

Write an awk program using function, which convert each word in a given text  into capital. 

a="UPPER CASE"
echo "$a" | awk '{print tolower($0)}'

Program- 15

Write a program for process creation using C. (Use of gcc compiler). 

#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
int main()
{
// make two process which run same
// program after this instruction
fork();
printf("Hello world!\n");
return 0;
}

Output:
Hello world!
Hello world!



G-MAIL: dystudymaterial2020@gmail.com


GTU NEW OOP-1 PRACTICALS: https://gtunewooppracticals.blogspot.com/2020/03/program-01-write-program-that-displays.html



SOURCE: https://www.darshan.ac.in//U888/StudyMaterial/DIET/3140702/3140702_OS_GTU_Study_Material_Lab-Manual_Operating-System-(3140702)_08052020072327AM.pdf

No comments:

Post a Comment

GTU NEW OS PRACTICALS

Program- 2 Write a shell script to generate mark sheet of a student. Take 3 subjects, calculate and display total marks, percentage and Cl...