Вы находитесь на странице: 1из 1

What is a shell? Explain its importance. A shell is a What is a filter? Explain any five filters in UNIX system.

ters in UNIX system. Write a shell script to check whether given year is a leap
program which is run every time a user log in and is known as a Ans. Filters are UNIX commands which are used for extracting year or not.
command interpreter. All the commands entered are run by the related information from a given file.Five mainly used filters in The script will be as –echo “Enter the Year : ”read year
shell. The prompt that appears when a user logs in is a shell and UNIX are – leap = `expr $year % 4` if test $leap –eq 0 then
waits for the user to enter a command. When a command is Paginating Files, ‘pr’ :- This command, i.e. ‘pr’, prepares a file echo “$year is a leap year.” Else echo “$year is not a leap
entered, the shell scans the command live for metacharacters, for printing by adding suitable headers, footers and formatted year” fi
i.e. characters that have a special meaning to the shell. After text. This command has to be used with a file name as an Explain the different types of variables in shell.
processing the metacharacters, the shell sends the command argument –$ pr emp.lst There are three types of variables commonly used in Bourne
line to the kernel for execution. The shell then displays the ‘head’ :- This command, as the name implies, displays the top of Shell scripts :
prompt for the next command. This interpretive cycle continues the file. When used without an option, it displays the first ten Environmental Variables : Sometimes called special shell
for the next command. That’s why shell is so important. lines of the file. When used with –n option, it displays the first variables, keyword variables, predefined shell variables, or
What is a process? Explain the mechanism of process ‘n’ number of lines. $ head emp.lst ,$ head –n 3 emp.lst standard shell variables, are used to tailor the operating
creation in UNIX system. ‘tail’ :- The tail command displays the end of the file(as opposite environment to suit your needs. Examples include PATH, TERM,
A process is born when a program starts execution and exists as to head command). Like head, it displays the last 10 lines when HOME and MAIL.
long as the program is running. After execution the process is used without arguments and with –n option, it displays the last User-Defined Variables : These are variables that we can create
said to die. The name of the process is usually the name of the ‘n’ number of lines. $ tail emp.lst, $ tail –n 4 emp.lst ourselves.
program being executed.The creation of a process is in three ‘cut’ :- The features of the ‘cut’ command will be illustrated with Positional Parameters : These are used by the shell to store the
phases and uses three system calls known as fork, exec and specific reference to the file “shortlist”, which stores the first values of command-line arguments.
wait. ‘fork’ is a system call that creates a new process from an five lines of ‘emp.lst’ file. We can extract both columns and What is the significance of write and talk command in
existing process. The new process is called the child process, fields from this file with the ‘cut’ command. Columns are UNIX.
and the existing process is called the parent. The attributes of specified with –c optionand fields with –f option. Ans. Write and talk are communication programs that allow
the parent and child are an identical image except for Cut is powerful text manipulator often used in combination with users to talk to each-other in a network.The “write” command
parameters like Parent-ID. The child gets a new Parent-ID and other commands or filters.Cut uses the tab as the default field copies lines from one user’s terminal to that of another user.
the process is forked. This is the mechanism used to multiply delimiter, but can also work with different delimiter. (A)‘grep’ :- The command is used by typing the following – $ write
process in the system. The child process overwrites the image The ‘grep’ command in UNIX is used to search for a pattern in a username
with a copy of program that is to be executed by using the given file. It displays the selected pattern, the line numbers or where username is another logged in user. The recipient gets a
‘exec’ system call. No additional processes are created and the the file names where the pattern occurs. The syntax is :$ grep message from the sender along with the sender’s username. If
existing program is replaced with a new program. The Parent-ID options pattern filename(s) (p)‘grep’ searches for pattern in the recipient of the message now writes back, communication
of this process is the same as that of the child process which one or more filenames. The first argument is the pattern and will start between the two users and continues until an end-of-
was forked.The ‘wait’ system call is executed by the parent ones remaining are filenames. file is read from the terminal or an interrupt is sent.
process to wait for the child process to get completed. The exit
status of the child process is picked up by the parent process.

Explain the output of the ls –l command. The command ls – . What is recursion? Which data structure is used for
l lists seven attributes of all the files in the working directory. recursion
The top list gives the file mode, which consists of a string of 10 Ans. Recursion is a process of defining a process/problem/an
characters. The first column gives the file mode, which consists object in times of itself.
of a string of 10 characters. The first character indicates the file The date structure used for Recursion is Stack data structure.
type. The nine characters after the file type are the file 7. What are the merits and demerits of recursion
permissions, which are displayed in three sets of three Ans. Merits of Recursion: - Mathematical functions such as
characters each. The second column gives the number of Fibonacci series generation can be easily implemented using
filenames or links associated with the file. The third column recursion as compared to iteration technique.
gives the file ownership. The third column displays the owner of Demerits of Recursion: - Many programming languages do
the file. The fourth column shows the group ownership of each not support recursion. Hence, recursive mathematical function
file. At the time of user account creation, the system is implemented using iterative methods.Even though
administrator assigns the user to a group. The fifth column mathematical functions can be easily implemented using
displays the file size in bytes. recursion. It is always at the cost of execution time and memory
Explain the different types of files in UNIX. space.
There are four possible types of file in UNIX:Ordinary files: 10. What is a binary tree? Write a note on its properties.
These files cannot contain text, data, or program information. A binary tree is made up of nodes when each node consists of
An ordinary file cannot contain another file, or directory. An three elements, left node, right node and a data element. The
ordinary file can be a text file or a binary file.Directory files: root node is the binary tree.Note on properties of a binary
Directories are containers that can hold files, and other tree :- The data key in the left child node needs to be smaller
directories. A directory is actually implemented as a file that has than or equal to the data key of its parent node. The data key in
one line for each item contained within the directory. the right child node needs to be greater than or equal to the
Special files: These files represent input/output (i/o) devices, data key of its parent node.
like a tty (terminal), a disk drive, or a printer. Because UNIX 11. Differentiate between static allocation and dynamic
treats such devices as files, some of the commands used to allocation
access ordinary files will also work with device files. This allows Ans. Static Allocation :- Static allocation means that the
for more efficient use of software.Links: A link is a pointer to memory allocation for representing the binary tree using 1-D or
another file. Since a directory is a list of the names and i- 2-D arrays is made statically at compile time.Dynamic
numbers of files, a directory entry can be a hard link, in which Allocation :- Dynamic allocation means that the binary tree
the i-number points directly to another file. using linked list is made dynamically at run time.

1. Hand simulate the sequential search algorithm on the 3. Hand simulate the insertion sort algorithm for the 8. Hand simulate the algorithm to find minimum and
data set given below and the search elements being 10, following data set maximum elements in a list of n elements
05, 76, 85, 200 10, 45, 80, 03, 39, 09, 55, 32, 43, 02, 07, 01, 10, 15 Algorithm : Max-Min
Data set: 10, 80, 03, 09, 55, 32, 100, 07, 05, 02, 12, 65, 63, 22, Algorithm : Insertion sort Input : p, q, the lower and upper limits of the dataset
92, 81, 48, 76 Input : n, Size of the input domain max, min, two variables to return the maximum and minimum
Ans. Algorithm : Sequential search Input : A, a[1….n], array of n elements values in the list
vector of n elemen Output : a[1….n] sorted Output : maximum and minimum values in the dataset
K, search element Method : Method : If (p= q) Then
Output : j – index of k for j=2 to n in steps of 1 do max=a(p) min=(q)
Method : i=1 While (i<n) item =a[j] Else If (p-q-1)Then
{If (A[n] =k){ i=j-1 If (p)>a(q) Then max= a(p) min=
write (“search is completed”) while ((i>=1) and a(q) else
write (“k is location of i”) (item<a[i]) do max= a(q) min= a(p)
exit (); } a [i+1] = a[1] If end Else
else i++ if end while i=i-1 m=(p+q)/2
end while end max-min(p,m,max1,min1)
write (“search unsuccessfully”); max-
Algorithm ends. a[i+1]= item min(m+1,q,max2,min2)
2. Hand simulate the binary search technique on the for end;Algorithm ends. max <-
dataset given in (16) for the same keys 4. Hand simulate the selection sort algorithm for the large(max1,max2)
Algorithm : Binary search dataset given in (18) min <-
Input : A, vector of n elements Ans. Algorithm : Selection sort small(min1.min2)
K, search element Input : n, Size of the input domain If end If end Algorithm ends.
Output : low – index of k a[1….n], array of n elements 9. Hand simulate the quicksort algorithm to sort a list of
Method : low=1, high Output : a[1….n] sorted data elements
While (low<=high-1) Method : Ans. Algorithm : QuickSort
{ Mid= (low+high)/2 for i=1 to n in steps of 1 do Input : p, q, the lower and upper limits of the listof
if (k<a[mid]) j=i elements A to be sorted
high=mid else low=mid if for k = i+1 to n in steps of Output : A,the sorted list
end } 1 do Method :
while end if (k=a [low]) if(a[k]<a[j]) If (p< q)
{ write (“search successful”) write (“k is at location low”) then j=k J=q+1;
exit ();}write (“search unsuccessfully”);if end; for end; PARTITION (p,j)
Algorithm ends. Interchange a[i] and QuickSort (P, j-1)
a[j] QuickSort (j+1, q)
For endAlgorithm ends. If endAlgorithm ends.

Вам также может понравиться