Operating System[2140702] 190280107068
Certificate
This is to certify that
Shri/Ms Aarohi R Mistry, Enrollment No.
190280107068 of B.E. Sem-4 class has
satisfactory completed the course in Operating
System-[2140702] within four walls of L. D.
College of Engineering, Ahmedabad-380015.
Date of submission. 30th April,2021
Staff in-Charge [Link]
Domadiya
Head of Department Dr. S. M. Shah
1
Operating System[2140702] 190280107068
Computer Engineering Department
L. D. College of Engineering Ahmedabad
VISION
• To achieve academic excellence in Computer Engineering by
providing value based education.
MISSION
• To produce graduates according to the needs of industry,
government, society and scientific community.
• To develop partnership with industries, research and
development organizations and government sectors for
continuous improvement of faculties and students.
• To motivate students for participating in reputed conferences,
workshops, seminars and technical events to make them
technocrats and entrepreneurs.
• To enhance the ability of students to address the real life issues by
applying technical expertise, human values and professional
ethics.
• To inculcate habit of using free and open source software, latest
technology and soft skills so that they become competent
professionals.
• To encourage faculty members to upgrade their skills and
qualification through training and higher studies at reputed
universities.
2
Operating System[2140702] 190280107068
Index
Title MARKS OUT OF 20
Sr. Page Grade Sign
C1 C2 C3 C4
No. No.
(5) (5) (5) (5)
1. Study of Basic commands of Linux/UNIX. 5
2. Study of Advance commands and filters of 6
Linux/UNIX.
3. Write a shell script to generate marksheet of a 9
student. Take 3 subjects, calculate and display
total marks, percentage and Class obtained by the
student.
4. Write a shell script to find factorial of given 11
number n.
5. Write a shell script which will accept a number b 12
and display first n prime numbers as output.
6. Write a shell script which will generate first n 14
fibonnacci numbers like: 1, 1, 2, 3, 5, 13,…
7. Write a menu driven shell script which will print 16
the following menu and execute the given task.
MENU
Display calendar of current month
Display today’s date and time
Display usernames those are currently
logged in the system
Display your name at given x, y position
Display your terminal number
Exit
3
Operating System[2140702] 190280107068
8. Write a shell script to read n numbers as 20
command arguments and sort them in descending
order.
9. Write a shell script to display all executable files, 23
directories and zero sized files from current
10. Write a shell script to check entered string is 26
palindrome or not.
11. Shell programming using filters (including grep, 29
egrep, fgrep)
12. Study of Unix Shell and Environment Variables 30
13. Write a shell script to validate the entered date. 31
(eg. Date format is : dd-mm-yyyy).
14. Write an awk program using function, which 34
convert each word in a given text into capital.
15. Write a program for process creation using C. (Use 35
of gcc compiler).
Grading Criteria (C1) Understanding Concepts Grading Scale : A – Above 17 (Excellent)
(C2) Logic Designing B – 13 to 16 (Good)
(C3) Program Execution C – 10 to 12 (Fair)
(C4) Final Output D – Below 10 (Poor)
A, B, C are Passing Grades. D is Failing Grade.
4
Operating System[2140702] 190280107068
Practical
SR No. 1
Command Work
1 ls Show all files and Directory
2 ls – a Show all hidden files and directory
3 ls – 1 Show files and directory one by one
4 ls -a-1 Shoe all hidden files and directory one b
5 man Show manual of command
6 date Show system date and time
7 cal Show month calendar
8 cal 08 2020 Show calendar of August month of 2020
9 cal 2020 Calendar of 2020 Year
10 Who Show Who is logged on
Study of Basic commands of Linux/UNIX.
Practical 2
5
Operating System[2140702] 190280107068
Study of Advance commands and filters of
Linux/UNIX.
SR Command Work
No.
1 du Estimate file space usage
2 ps How many process running
3 wc test1 Print new line, word and count
bytes for each files
4 cat test1 Show data of the file
5 Cat>test5 Make a new file and input data
to file
6 Cat test2>test3 Write data of test 2 over test 3
7 Uname Print System information
8 Cd Change directory
9 mkdir Make a new directory
10 cd.. Coming out from directory
11 Rmvdir directoryname Remove directory
12 Rmv filename Delete file
13 cp Duplicate the contents of source
file to target files
14 mv Changes the name of File or
Directory
Filters in Linux/UNIX
Filters are programs that take plain text(either stored in a file or produced by
another program) as standard input, transforms it into a meaningful format, and
6
Operating System[2140702] 190280107068
then returns it as standard output. Linux has a number of filters. Some of the
most commonly used filters are explained below:
1. cat : Displays the text of the file line by line.
Syntax:
cat [path]
2. head : Displays the first n lines of the specified text files. If the number of lines
is not specified then by default prints first 10 lines.
Syntax:
head [-number_of_lines_to_print] [path]
3. tail : It works the same way as head, just in reverse order. The only difference
in tail is, it returns the lines from bottom to up.
Syntax:
tail [-number_of_lines_to_print] [path]
4. sort : Sorts the lines alphabetically by default but there are many options
available to modify the sorting mechanism. Be sure to check out the man page
to see everything it can do.
Syntax:
sort [-options] [path]
5. uniq : Removes duplicate lines. uniq has a limitation that it can only remove
continuous duplicate lines(although this can be fixed by the use of piping).
Assuming we have the following data.
Syntax:
uniq [options] [path]
When applying uniq to sorted data, it removes the duplicate lines because, after
sorting data, duplicate lines come together.
7
Operating System[2140702] 190280107068
6. wc : wc command gives the number of lines, words and characters in the data.
Syntax:
wc [-options] [path]
7. grep : grep is used to search a particular information from a text file.
Syntax:
grep [options] pattern [path]
8. tac : tac is just the reverse of cat and it works the same way, i.e., instead of
printing from lines 1 through n, it prints lines n through 1. It is just reverse of cat
command.
Syntax:
tac [path]
9. sed : sed stands for stream editor. It allows us to apply search and replace
operation on our data effectively. sed is quite an advanced filter and all its
options can be seen on its man page.
Syntax:
sed [path]
10. nl : nl is used to number the lines of our text data.
Syntax:
nl [-options] [path]
Practical 3
8
Operating System[2140702] 190280107068
Write a shell script to generate marksheet of a
student. Take 3 subjects, calculate and display total
marks, percentage and Class obtained by the
student.
9
Operating System[2140702] 190280107068
OUTPUT:-
Practical 4
10
Operating System[2140702] 190280107068
Write a shell script to find factorial of given
number n.
OUTPUT:
Practical 5
11
Operating System[2140702] 190280107068
Write a shell script which will accept a
number b and display first n prime numbers
as output.
OUTPUT
12
Operating System[2140702] 190280107068
Practical 6
13
Operating System[2140702] 190280107068
Write a shell script which will generate first
n fibonnacci numbers like: 1, 1, 2, 3, 5, 13,…
14
Operating System[2140702] 190280107068
OUTPUT
Practical 7
15
Operating System[2140702] 190280107068
Write a menu driven shell script which will print
the following menu and execute the given task.
Display
calendar of current month
Display
today’s date and time
Display
usernames those are currently logged in
the system
Display your
name at given x, y position
Display your
terminal number
Exit
echo "[Link] List of Directary"
echo "[Link] File"
echo "[Link] a file"
echo "[Link] a file"
16
Operating System[2140702] 190280107068
echo "[Link] a file"
echo "[Link]"
echo "enter Your Choice"
read i
case "$i" in
1) ls ;;
2) echo "enter which file you want to copy"
read f1
echo "enter destination file"
read $f6
cp $f6 -> $f1
echo "file copied sucessfully";;
3) echo "enter file name which you want to change"
read f2
echo "enter new name"
read f3
mv $f2 $f3
echo "renamed sucessfully";;
4) echo "enter file name which you want to delete"
read f4
17
Operating System[2140702] 190280107068
rm $f4
echo "file deleted sucessfully";;
5) echo "enter filename which you want to edit"
read f5
nano $f5;;
6) exit;;
*) echo "enter choice correctly";;
Esac
OUTPUT
18
Operating System[2140702] 190280107068
19
Operating System[2140702] 190280107068
Practical 8
Write a shell script to read n numbers as
command arguments and sort them in
descending order.
echo "enter size of array"
read n
for((i=0;i<$n;i++))
do
echo "enter number"
read a[$i]
done
echo "intial array"
for((i=0;i<$n;i++))
do
echo ${a[i]}
done
for((i=0;i<$n;i++))
20
Operating System[2140702] 190280107068
do
for((j=0;j<$n -i-1 ; j++))
do
if [ ${a[$j]} -lt ${a[$((j+1))]} ]
then
t=${a[j]}
a[$j]=${a[$((j+1))]}
a[$((j+1))]=$t
fi
done
done
echo "Array in desending order"
for((i=0;i<$n;i++))
do
echo ${a[i]}
done
OUTPUT
21
Operating System[2140702] 190280107068
22
Operating System[2140702] 190280107068
Practical 9
Write a shell script to display all
executable files, directories and zero
sized files from current
Directory
GNU nano 4.9
pf12
echo "Excecutable File"
for file in *
do
if [ -f $file ]
then
echo $file
fi
done
echo "using another command "
find . -type f
23
Operating System[2140702] 190280107068
echo "directories "
for d in * /
do
echo $d
done
echo "zero size file"
find . -size 0
OUTPUT
24
Operating System[2140702] 190280107068
25
Operating System[2140702] 190280107068
Practical 10
Write a shell script to check entered string is
palindrome or not.
clear
echo "enter string which you want to check"
read str
len=`echo $str | wc -c`
len=`expr $len - 1`
echo "Length=$len"
c=0
while test $len -ge $c
do
d= `echo $str | cut -c $len`
echo "$d"
len=` expr $len -1`
done
26
Operating System[2140702] 190280107068
len=`echo $str | wc -c`
len=`expr $len - 1`
i=1
j=`expr $len / 2`
while test $i -le $j
do
k=`echo $str | cut -c $i`
l=`echo $str | cut -c $len`
if test $k != $l
then echo "String is not palindrome"
exit
fi
i=`expr $i + 1`
len=`expr $len -1`
done
echo "String is palindrome"
27
Operating System[2140702] 190280107068
OUTPUT
28
Operating System[2140702] 190280107068
Practical 11
Shell programming using filters (including grep,
egrep, fgrep)
29
Operating System[2140702] 190280107068
Practical 12
Study of Unix Shell and Environment
Variables.
30
Operating System[2140702] 190280107068
Practical 13
Write a shell script to validate the entered
date. (eg. Date format is : dd-mm-yyyy).
clear
echo "enter date"
read dd
echo "enter month"
read mm
echo "enter Year"
read yyyy
days=0
if [ $mm -le 0 -o $mm -gt 12 ]
then
echo "month is invalid"
exit 1
fi
case $mm in
1)days=31;;
31
Operating System[2140702] 190280107068
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
if [ $mm -eq 2 ]
then
if [ $((yyyy % 4 )) -eq 0 ]
then
days=29
fi
fi
32
Operating System[2140702] 190280107068
if [ $dd -le 0 -o $dd -gt $days ]
then
echo "date is invalid"
exit 3
fi
echo "$dd-$mm-$yyyy is a valid date"
OUTPUT
33
Operating System[2140702] 190280107068
Practical 14
Write an awk program using function,
which convert each word in a given text
into capital.
echo -n "enter your name"
read name
echo "$name" > cat >file
gawk '{print toupper($0)}' file
OUTPUT
34
Operating System[2140702] 190280107068
Practical 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() {
pid_t pid, mypid, myppid;
pid = getpid();
printf("Before fork: Process id is %d\n", pid);
pid = fork();
if (pid < 0) {
perror("fork() failure\n");
return 1;
35
Operating System[2140702] 190280107068
// Child process
if (pid == 0) {
printf("This is child process\n");
mypid = getpid();
myppid = getppid();
printf("Process id is %d and PPID is %d\n", mypid, myppid);
} else { // Parent process
sleep(2);
printf("This is parent process\n");
mypid = getpid();
myppid = getppid();
printf("Process id is %d and PPID is %d\n", mypid, myppid);
printf("Newly created process id or child pid is %d\n", pid);
return 0;
36
Operating System[2140702] 190280107068
OUTPUT
*****
37