OS Practicals
-
Upload
george-matthew -
Category
Documents
-
view
246 -
download
0
Transcript of OS Practicals
-
8/10/2019 OS Practicals
1/21
UNIVERSITY OF MUMBAI
INSTITUTE OF DISTANCE AND OPEN LEARNING (IDOL)*
*(Institute Of Distance Education (IDE) is renamed)
CERTIFICATE
THE EXPERIMENTS DULY SIGNED IN THIS JOURNAL REPRESENT
THE BONIFIED WORK BY MR.
ROLL NO. IN SEMESTER II OF FIRST YEAR OF MASTER IN
COMPUTER APPLICATION (MCA) IN THE COMPUTER LABORATORY
OF PCP CENTER SHREE RAM COLLEGE, BHANDUP FOR SUBJECTOPERATING SYSTEM DURING ACADEMIC YEAR 2013-14.
LECTURE IN CHARGE HEAD OF DEPARTMENT OF MCA
EXTERNAL EXAMINER
-
8/10/2019 OS Practicals
2/21
-
8/10/2019 OS Practicals
3/21
Practical No. :1
Aim: To Study basic commands of Linux
$whoUser ttyl1 Apr 15 11:47
$who am iUser ttyl1 Apr 15 11:47
$pwd/home/user
$tty/dev/tty10
$unameUWIN-NT
$uname -aUWIN-NT user-0294fee (22062001)-5.12600 2600 il586
$uname -pI386
$uname -r(22062001)-5.12600
$uname -helpUname: -h: unknown optionUname: -e: unknown optionUsage: uname [-ailmnprsv][-S name]
$factor 15-ksh: factor: notfound [No such file or directory]
$bcBc 1.04Copyright (C) 1991,1992,1994,1997 Free Software Foundation, Inc.This is Free Software with ABSOLUTELY NO WARRANTY.For fetails type warranty./*Division*/10/2510.0/2510/2.5
4/*Multiplication*/
-
8/10/2019 OS Practicals
4/21
85*2170/*Square root*/Sqrt(121)11
/*Addition*/2.5+2.55.0/*Loop*/For(i=5;i
-
8/10/2019 OS Practicals
5/21
$ ls -l
total 3600
-rw-r--r-- 1 user None 52 Apr 16 11:12 newfile
$ touchUsage: touch [-ancfmv] [-r file] [-t|d time] [ date ] file ...
$ mkdir newdir
$ cd newdir
-
8/10/2019 OS Practicals
6/21
Practical No. :2
Aim : To study advanced commands of Linux
$ tree
-ksh: tree: not found [No such file or directory]
$ alias p='ping'
$ p 192.168.1.2
Pinging 192.168.1.2 with 32 bytes of data:
Reply from 192.168.1.2: bytes=32 time
-
8/10/2019 OS Practicals
7/21
D
E
H
$ grep A newfileMy name is Abc
$ grep s newfile
My name is Abc
I am a IDE student
My roll no is 123
$ grep a newfile
My name is Abc
I am a IDE student
$ grep Abc newfile
My name is Abc
$ grep My newfile
My name is Abc
My roll no is 123
$ du1 ./newdir
10
$ cat > emp.lst
9876|sam dsilva | director|23/04/2010/7000
7896|david fernando|director|15/09/2009|800
$ sed -n '1,2p' emp.lst
9876|sam dsilva | director|23/04/2010/7000
7896|david fernando|director|15/09/2009|800
$ sed -n '1,2w temp' emp.lst
$ cat temp
9876|sam dsilva | director|23/04/2010/7000
7896|david fernando|director|15/09/2009|800
-
8/10/2019 OS Practicals
8/21
Practical No. :3
Aim: Bash shell to rename the file which change in the suffix
$ ls -ltr
total 5
-rw-r--r-- 1 user None 174 Apr 16 11:48 emp.lst
-rw-r--r-- 1 user None 104 Apr 16 11:51 newfile
-rw-r--r-- 1 user None 12 Apr 16 11:52 AtoH
drwxr-xr-x 2 user None 512 Apr 16 11:53 newdir
-rw-r--r-- 1 user None 174 Apr 16 11:54 temp
$ for file in *.lst; do
> ln=`basename $file .lst`
> mv $file $ln.txt
> done
$ ls -ltr
total 5
-rw-r--r-- 1 user None 174 Apr 16 11:48 emp.txt
-rw-r--r-- 1 user None 104 Apr 16 11:51 newfile
-rw-r--r-- 1 user None 12 Apr 16 11:52 AtoH
drwxr-xr-x 2 user None 512 Apr 16 11:53 newdir-rw-r--r-- 1 user None 174 Apr 16 11:54 temp
-
8/10/2019 OS Practicals
9/21
Practical No. :4
Aim : gcc and g++ compiler program to find factorial of a number
$ cat > factorial.c
#include
int main()
{
int n,fact,i;
fact=1;
printf("Enter the no.");
scanf("%d",&n);
for(i=n;i>0;i--)
{
fact=fact*i;}
printf("\nFactorial of %d is %d\n',n,fact);
return 0;
}
Output:
gcc factorial.c
./a.outEnter the no. 5
Factorial of 5 is 120
-
8/10/2019 OS Practicals
10/21
Practical No. :5
Aim : gcc and g++ compiler program to find whether a number is prime or not.
$ cat > factorial.c
#include
int main()
{
int n,i;
printf("Enter the no.");
if(n==0)
{
printf("\nNumber is zero");
exit(0);
}if(n==1||n==2)
{
printf("\n%d is prime number",n);
}
else
{
for(i=3;i
-
8/10/2019 OS Practicals
11/21
Practical No. :6
Aim : Write a menu-driven program to display calendar, date , time , username,
name of the user displayed on x & y co-ordinates & terminal number.
$ cat > menu.sh
#!/bin/bash
echo "Your choice"
choice=1
while test $choice -ne 0
do
echo "choices are:"
echo "1. Print Calendar"
echo "2. Print date"echo "3. Print username"
echo "4. Terminal Number"
echo "0. Exit"
echo "Enter your choice:"
read choice
case $choice in
1) date;;
2) cal;;
3) who;;4) tty;;
0) exit;;
*) echo "invalid input"
esac
done
Output:
$ sh menu.sh
Your choice
choices are:
1. Print Calendar
2. Print date
3. Print username
4. Terminal Number
0. Exit
Enter your choice:
1
Sat Apr 16 12:49:41 IST 2011
choices are:1. Print Calendar
-
8/10/2019 OS Practicals
12/21
-
8/10/2019 OS Practicals
13/21
-
8/10/2019 OS Practicals
14/21
Practical No. :8
Aim: Write a shell script to validate an entered date
$ cat > valid.sh
#!/bin/bash
echo "Enter the date to validate"
echo "DD"
read dd
echo "MM"
read mm
echo "YYYY"
read yyyy
if [ $dd -gt 31 ] ; thenecho "Invalid date"
elif [ $mm -gt 12 -o $yyyy -le 0 ]
then
echo "Invalid month"
elif [ $yyyy -gt 9999 -o $yyyy -le 999 ]
then
echo "Invalid year"
else
echo "Your date is valid"echo "$dd/$mm/$yyyy"
fi
Output:
$ sh valid.sh
Enter the date to validate
DD
06
MM
01
YYYY
1989
Your date is valid
06/01/1989
$ sh valid.sh
Enter the date to validate
DD
32MM
-
8/10/2019 OS Practicals
15/21
-
8/10/2019 OS Practicals
16/21
Practical No. :9
Aim: Write a shell script to calculate area of circle, rectangle, square and
triangle.
$ cat > area.sh
#!/bin/bash
echo "Your choice"
choice=1
while test $choice -ne 0
do
echo "Choices are: "
echo "1. Area of Circle"
echo "2. Area of Square"
echo "3. Area of Rectangle"echo "4. Area of Traingle"
echo "0. Exit"
echo "Enter your choice"
read choice
case $choice in
1) echo "Enter the radius"
read r
echo "The area of circle is "
echo 3.14\*$r\*$r | bc;;2) echo "Enter the side of square"
read side
echo "The area of square is "
echo $side\*$side | bc;;
3) echo "Enter the length"
read lr
echo "Enter the breadth"
read br
echo "The area of rectangle is "
echo $lr\*$br | bc ;;
4) echo "Enter the base length"
read bs
echo "Enter the height"
read hg
echo "The area of triangle is "
echo 0.5\*$bs\*$hg | bc ;;
0) exit ;;
*) echo "Invalid input";;
esacdone
-
8/10/2019 OS Practicals
17/21
Output:
$ sh area.sh
Your choice
Choices are:
1. Area of Circle2. Area of Square
3. Area of Rectangle
4. Area of Traingle
0. Exit
Enter your choice 1
Enter the radius
1
The area of circle is
3.14
Choices are:1. Area of Circle
2. Area of Square
3. Area of Rectangle
4. Area of Traingle
0. Exit
Enter your choice
2
Enter the side of square
4The area of square is
16
Choices are:
1. Area of Circle
2. Area of Square
3. Area of Rectangle
4. Area of Traingle
0. Exit
Enter your choice
3
Enter the length
3
Enter the breadth
4
The area of rectangle is
12
Choices are:
1. Area of Circle
2. Area of Square3. Area of Rectangle
-
8/10/2019 OS Practicals
18/21
-
8/10/2019 OS Practicals
19/21
Practical No. :10
Aim: To generate mark sheet using file handling
$ cat > db1
#!/bin/bash
i=2
while [ $i -le 6 ]
do
case $i in
2) sed -n '2w temp' database ;;
3) sed -n '3w temp' database ;;
4) sed -n '4w temp' database ;;
5) sed -n '5w temp' database ;;
6) sed -n '6w temp' database ;;
esacm1=`cut -d " " -f3 temp`
m2=`cut -d " " -f4 temp`
m3=`cut -d " " -f5 temp`
total=`expr $m1 + $m2 + $m3`
i=`expr $i + 1`
per=`expr $total / 3`
echo "Total = $total, Percentage = $per"
done
$ cat > database
roll name m1 m2 m3
1 neha 80 90 90
2 seema 80 80 90
3 puja 70 90 80
4 priya 80 90 50
5 prachiti 60 80 70
Output:
$ sh db1
Total = 260, Percentage = 86
Total = 250, Percentage = 83
Total = 240, Percentage = 80
Total = 220, Percentage = 73
Total = 210, Percentage = 70
-
8/10/2019 OS Practicals
20/21
Practical No. :11
Aim : To write a script which accepts 2 strings, find the length of the string,
concatenate both the strings & print the string in reverse.
$ cat > stringfun.sh
#!/bin/bash
echo "Enter the string 1"
read str1
echo "Enter the string 2"
read str2
choice=1
while [ $choice -ne 0 ]do
echo "enter 1 => String length"
echo "enter 2 => String concatenation"
echo "enter 3 => Reversing the string"
echo "enter 0 => exit"
read choice
case $choice in
1) echo "The length of the first string is "
n=`expr $str | wc -c`echo $n
echo "The length of the second string is "
n=`expr $str2 | wc -c`
echo $n
;;
2) echo "The concatenated string is "
echo $str1|$str2;;
3) echo "The reversed string is: "
z=`echo $str1 | wc -m`
while test $z -gt 0
do
echo -n `echo $str1 | cut -c $z`
done
;;
esac
done
-
8/10/2019 OS Practicals
21/21
Output:
$ sh stringfun.sh
Enter the string 1
MumbaiEnter the string 2
Indians
enter 1 => String length
enter 2 => String concatenation
enter 3 => Reversing the string
enter 0 => exit
1
The length of the first string is
7
The length of the second string is8
enter 1 => String length
enter 2 => String concatenation
enter 3 => Reversing the string
enter 0 => exit
2
The concatenated string is
MumbaiIndians
enter 1 => String lengthenter 2 => String concatenation
enter 3 => Reversing the string
enter 0 => exit
0