MCS 045
MCS 045
The assignment has two parts A and B. Answer all the questions. Each part is for 20
marks. UNIX and DBMS lab record carries 40 Marks. Rest 20 marks are for viva voce. You
may use illustrations and diagrams to enhance the explanations. Please go through the
guidelines regarding assignments given in the MCA Programme Guide for the format of
presentation. If any assumptions made, please state them.
PART-I: MCS-041
Question 1:
To kill a process we must first note the PID of the process to be killed using the ps
cpmmand. e.g.
$ cat employee.dat | grep ‘Nagpur’ | sort > output.dat &
6173
$
If the above background process is to be killed we must execute the following command
$ kill 6173
6173 Terminated.
(b) To append the contents of file2 after the contents of the file1 and redirect them to a new
file3.
Ans: $ cat file1 file2 > file3
(c) To print the first difference between any two given files.
Ans:
cmp :- Compares two files, and if they differ, tells the first byte and line number where
they differ.
We can use the `cmp' command to show the offsets and line numbers where two files
differ. `cmp' can also show all the characters that differ between the two files, side by
side.
SYNTAX
cmp options... FromFile [ToFile]
cmp file1 file2
(e) To grant the permissions of read, write and execute to the user and read only to the
group and others for all the files in a current directory.
Ans: The permissions signify who all can access the file, and for what purpose. This is
decided by the file permissions. A set of nine characters denote these permissions. There
are three types of permissions to a file:
r read
w write
x execute
There are three entities to which any combination of these permissions are assigned.
These entities are the owner, the group, and the rest. Of the nine characters, the first
three characters decide the permissions held by the owner of the file. The next set of
three characters specify the permissions for the other users in the group to which the file
owner belongs, while the last set decides the permissions for the users outside the group.
Out of the three characters belonging to each set the first character is for indicating the
‘read’ permission, the second character is for ‘write’ and the last is for ‘execute’
permission.
We know that directories too are treated by Unix as files. A directory, as Unix perceives, is
a file which contains the names of the files present in the directory. So, if a owner has to
be granted read, write and execute and group and others can only read the directory, the
permission will be
r w x r- - r - -
(f) To direct a standard output to any of the line printer.
Ans: The lp command is used to send the user’s print job to the print queue. When we
submit the job for printing using the lp command it returns a ‘request id’. This id can be
used to keep track of our job or to cancel it if required. When we cancel the print request
our job gets removed from the print queue
The standard output can be redirected to a file or a printer. Unix provides redirection
symbol for the purpose. The symbol > implies redirection of output. The > operator tells
Unix, “Don’y display this output on screen instead, put it somewhere else”.
$ cat file1 > lp
This will send the content of file1 to lp
(g) To list all the files in the current directory whose file names starts with a.
Ans:
$ ls a*
(h)
(i) To split a file splittest, which is containing 20 lines into 5 lines each which are directed to
four various files.
Ans:
$ split -25 < splittest
Question 2:
(a) Write a shell program to count no. of characters, no. of blank spaces, no. of
words and no. of lines in a given file by the user.
#!/bin/bash
# to count no. of chars, no. of blank spaces, no. of words and no. of lines in a given file by the
user
str=" "
i=0
temp=' '
len=0
cchar=0
cbspace=0
cwords=0
clines=0
i=`expr $i + 1`
done
#!/bin/bash
# to find the day when a date is given
set -A arr
#!/bin/bash
# display the largest element in a given 4X4 matrix
Max=0
outer=1 # Set outer loop counter.
# ===============================================
# Beginning of inner loop.
for b in 1 2 3 4
do
echo "Pass $inner in inner loop."
let "inner+=1" # Increment inner loop counter.
echo "Enter a number"
read num
if [$num –ge $max]
then
max=`expr $num`
fi
done
# End of inner loop.
Question 1:
(d) Write appropriate triggers, exceptions and functions for the above employee
database schema.
Ans:
Table created.
Table created.
Table created.
SQL> INSERT INTO RIKS_DEPARTMENT
2 (DEPT_NO,DEPT_NAME,MANAGER)
3 VALUES(101,'ACCOUNT','Mr. RAJESH KUMAR');
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
SQL> SELECT * FROM RIKS_EMPLOYEE;
6 rows selected.
1 row created.
1 row created.
1 row created.
1 row created.
Ans: (b)
ENAME ESSN
---------------------------------------- ----------
DEPEND_NAME RELATION DOB
---------------------------------------- --------------- ---------
Mr. AJAY KUMAR 5076
MRS. SHALINI KUMAR WIFE 25-JAN-82
MANAGER
----------------------------------------
Mr. RAJESH KUMAR
DOB
---------
21-FEB-99
Ans©
Procedures:
END;
END;
END;
SELECT D.MANAGER
FROM RIKS_DEPARTMENT D, RIKS_EMPLOYEE E
WHERE D.DEPT_NO=E.DEPT_NO AND
E.ESSN=5078;
SELECT D.DOB
FROM RIKS_DEPENDENT D, RIKS_EMPLOYEE E
WHERE D.ESSN=E.ESSN AND
D.RELATION='SON' AND
E.ESSN=5078;
END;