Download Date: 14-08-2012

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
USN
1 P E
PESIT Bangalore South Campus
Hosur road, 1km before Electronic City, Bengaluru -100
Department of Computer Science And Engineering
INTERNAL ASSESSMENT TEST – 1
Date
: 23.2.2016
Subject & Code : UNIX and Shell Programming(10CS44)
Name of Faculty : Prof. Ajoy Kumar
Max Marks : 50
Section
: A,B,C(CSE/ISE)
Time
: 11:30-1:00 PM
Note: All Questions are compulsory
1. a
With a neat diagram, explain the architecture of UNIX Operating System
Solution: [3 Divisions 2 M each Diagram 1M]
Ans: The unix architecture mainly consists of of 3 divisions:

Division of labor:Kernel and Shell
Division of labor between two agencies the kernel and shell.The kernel interacts
with the machine's hardware, and the shell with the user.The kernel is core of operating
system-a collection of routines mostly written in C.It is loaded into memory when the
system is booted and communicates directly with the hardwarte.User programs-To use
the hardware through a set of functions called the system calls.Kernel manages the
system's memory,schedules processes,decides their priorities and performs other
tasks.This is called the operating system-a program's gateway to the computer's
resources.Command interpreter is actually the interface between the user and kernel.
B.E IV Semester
7
USN
1 P E
PESIT Bangalore South Campus
Hosur road, 1km before Electronic City, Bengaluru -100
Department of Computer Science And Engineering
Kernel-Shell relationship diagram

The file and process
Two simple entities support the Unix system-the file and process where files have places
and processes have life.A file is just an array of bytes and can contain virtually anything.It
contains directories and dominant file type is text.The secondary entity is the
process,which is the name given to a file when it is executed as a program.Processes have
parents,chidren and grandchildren,and are born and die.

The system calls
These are handful of functions used to communicate with the kernel.All UNIX flavours use
the same system calls.These system calls are built into the kernel,and interaction through
them represents an efficient means of communication with the system.
B.E IV Semester
USN
1 P E
PESIT Bangalore South Campus
Hosur road, 1km before Electronic City, Bengaluru -100
Department of Computer Science And Engineering
b Explain the following commands with example
2
i) gzip: used to compress the files.It provides extension .gz to the compressed file 1M
options:gzip –d  Uncompressing a file
gzip –r Recursive compression
example: gzip abc.html
gzip –d abc.html
ii)tar: Used to create disk archive that contains a group of files or an entire directory
structure
1M
options:
-C: Create an archive
-X: Extract files from archive
-t: Display files in archive
-f arch :Specify the archive arch
c
Create a file A.txt that contains 5 student details. Copy first 3 student details to another
file B.txt and delete A.txt file
Solution:
Cat A.txt
01|ABC1
02|ABC2
03|ABC3
04|ABC4
05|ABC5
$ rm A.txt
B.E IV Semester
1
USN
1 P E
PESIT Bangalore South Campus
Hosur road, 1km before Electronic City, Bengaluru -100
Department of Computer Science And Engineering
2. a
Explain briefly absolute path name and relative path name with examples.
Solution:
Absolute pathname: (2.5 marks)
If the first character of the pathname is /,the file's location must be determined with
respect to root(the first /).Such a pathname is called as absolute
pathname.(Eg:/home/kumar/login.sql).When we have more than one / in a pathname,for
each such /,you have to descend one level in the file system.No two files in a UNIX system
can have identical absolute pathnames.
Using absolute pathname for a command:
Eg;
$ /bin/date
Relative pathname: (2.5 marks)
If the first character of the pathname is not /,.Such a pathname is called as relative
pathname.Relative pathnamkes can be distinguished using . and . . in the pathname.

. (a single dot) --This represents the current directory

. . (two dots) – This represents the parent directory
cd .. ---Moves one level up
cd../.. ---Moves two levels up
cd..
A filename can begin with a dot
cp ../sharma/.profile
B.E IV Semester
5
USN
1 P E
PESIT Bangalore South Campus
Hosur road, 1km before Electronic City, Bengaluru -100
Department of Computer Science And Engineering
b Explain with diagram 3 different modes in which Vi editor works
5
Diagram 2M each mode 1M
vi editor mainly consists of 3 modes:
3. a

Command mode:The default mode of the editor where every key pressed is
interpreted as a command to run on text.This mode is used to copy and delete the
text.

Input mode:Every key pressed after switching to this mode actually shows up as
text.This mode is invoked by pressing any one of the following keys:(i,a,IA,o,O,R,S,s,rch)

ex mode(Last Line mode):This mode is used to handle the files and perform
substitution. Pressing a : in the command mode invokes this mode.This is carried
out by pressing any one of the following keys:-(:w,:x,:wq,:q)
Explain standard input, standard output and standard error with respect to UNIX
4
Operating System
Solution:
The shell associates three files with the terminal-two for the display and one for the
keyboard. These special files are actually streams of characters which many commands
see as input and output. A stream is simply a sequence of bytes. Each stream is associated
with a default device, and generically this device is a terminal.

Standard Input

Standard Output

Standard error
B.E IV Semester
USN
1 P E
PESIT Bangalore South Campus
Hosur road, 1km before Electronic City, Bengaluru -100
Department of Computer Science And Engineering
b What are wild cards? Explain shells wild cards with example
6
Solution:
The metacharacters that are used to construct the generalized pattern for matching
filenames belong to a category called wild cards. This pattern is framed with ordinary
characters and a metacharacter using well defined rules. The pattern can then be used as
an argument to the command, and the shell will expand it suitably before the command is
executed.
Explanation of the following wild cards with examples.

*

?

[ijk]

[x-z]

[!ijk]

[!x-z]
B.E IV Semester
USN
1 P E
PESIT Bangalore South Campus
Hosur road, 1km before Electronic City, Bengaluru -100
Department of Computer Science And Engineering
4. a
A file’s current permissions are rw_r_xr_ _.Specify the chmod expression required to
change them for the following
i) rwx rwx rwx ii) r_ _r_ _r_ _ _ iii) _ _ _r_ _r_ _ iv) _ _ _ _ _ _ _ _ _(1.5marks each)
using both the relative and absolute methods
Solution:
i)
rwx rwx rwx
Using Relative
$chmod ug0+rwx file
Or
$chmod u+x file
$chmod g+w file
$chmod o+wx file
Using Absolute
$chmod 777 file
ii)
r_ _r_ _r_ _ _
Using relative
$chmod u-w file
$chmod g-x file
Using absolute
$chmod 444 file
iii)
_ _ _r_ _r_ _
Using relative
$chmod u-rx file
$chmod g-x file
Using absolute
$chmod 044 file
iv)
_________
Using relative
$chmod u-rw file
$chmod g-rx file
$chmod o-r file
Using absolute
$chmod 000 file
B.E IV Semester
6
USN
1 P E
PESIT Bangalore South Campus
Hosur road, 1km before Electronic City, Bengaluru -100
Department of Computer Science And Engineering
b Explain briefly file attributes listed using ls - l command
Solution: File attributes of ls-l
5. a

File type and permissions

Links

Ownership

Group ownership

File size

Last modification time

File name
Explain the following commands with example
i)
Comm: This command is used to display differencing and common entries in
two files (1M)
ii)
iii)
diff : This command can be used to list the differences between the two files
It also lists which lines in one file need to be changed to make both the
files similar (1M)
passwd : This command is used to change the password
Example: $ passwd (2M)
iv)
stty: This command is used to change and display the settings of the terminal
Example: $stty -a ,displays the current settings
stty – echo, turns off keyboard input (2M)
v)
who : This command is used to display all the users(2M)
options: -Hu : to provide more details
$ who am I
: is used to know the user who invoked the
command
vi) tee : tee is an external command and not a feature of shell. It handles a character
stream by duplicating its input. It saves one copy in a file and writes the other to standard
output.
(2M)
B.E IV Semester
4
10
USN
1 P E
PESIT Bangalore South Campus
Hosur road, 1km before Electronic City, Bengaluru -100
Department of Computer Science And Engineering
********
B.E IV Semester