1 Usp - I Test Solution

  • June 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View 1 Usp - I Test Solution as PDF for free.

More details

  • Words: 3,051
  • Pages: 11
1 USP - I TEST SOLUTION

1. (a) Explain the architecture of UNIX operating system. 08 Ans: In UNIX the division of labour is between two agencies-the kernal and the shell.the kernal interacts with the machine’s hardware, the shell with the user. kernal:-the kernal is the core of the operating system-a collection of routines mostly written in c.these routines communicate with the hardware directly.it is that part of the unix system that is loaded into memory when the system is booted.user progams(the applications) that need to communicate with the hardware(like the hard disk or the terminal) use the services of the kernal,which performs the job on the user’s behalf.these programs access the kernal through a set of functions called system calls.kernal also manages the system’s memory,schedules processes,decides their priorities. Shell:-it is actually the interface between the user and the kernal.even though there’s only one kernal running on the system, there could be several shells in action-one for each user who is logged in. System calls: these are the functions to communicate with the kernal.often the same system call can access both a file and a device.these system calls are built into the kernal, and interaction through them represents an efficient means of communication with the system.

1. (b) Explain POSIX

02

Ans: the POSIX (Portable Operating System Interface for Computer Environments) standard refers to a group of related standards for operating systems in general, but was based on UNIX because UNIX was supposedly free from bias on account of its vendor-neutrality.two of the most –cited standards from the POSIX family are known as POSIX.1 and POSIX.2.POSIX.1 specifies the c application program interface-the system calls.POSIX.2 deals with the shell and utilities. 2. (a) Explain the salient features of the unix operating system 08 Ans: the features of the UNIX operating system are:

1. The File and Process A file to UNIX is just an array of bytes and can contain virtually anything-text, object code or a directory structure.unix provides a vast array of text manipulation tools that can edit these files without using an editor. The second entity is the process, which is the name given to a file when it is executed as a program.like files, processes also belong to a separate hierarchical tree structure.

2

2. UNIX:a multiuser system in unix, the resources are actually shared between all users.the computer breaks up a unit of time into several segments, and each user is allotted a segment.so at any point in time, the machine will be doing the job of a single user.the moment the allocated time expires, the previous job is kept in abeyance and the next user’s job is taken up.this process goes on till the circle has turned full-circle and the first user’s job is taken up once again.

3. UNIX: a multitasking system A single user can also run multiple tasks concurrently; the kernal is designed to handle a user’s multiple needs.

4. The building- block approach Many UNIX tools are designed with the requirement that the output of one tool be used as input to another.

5. The UNIX Toolkit Unix represents the kernal, but the kernal by itself can’t do anything that can benefit the user.To properly exploit the power of unix, we need to use the host of applications that are shipped with every unix system.There are general-purpose tools,text manipulation utilities(called filters),compilers and interpreters,networked applications and system administration tools. 6. Pattern matching The *(known as a metacharacter) is a special character used by the system to indicate that it can match a number of filenames.unix features elaborate pattern matching schemes that use several characters from this matacharacter set.

7.

Programming Facility The UNIX shell is also a programming language.It has all the necessary ingredients, like control structures, loops and variables, that establish it as a powerful programming language in its own right.these features are used to design shell scripts-programs that also include UNIX commands in their syntax

3 8. Documentation The principle on-line help facility available is the man command, which remains the most important reference for commands and their configuration files.

2. (b) Explain tput, exit commands

02

Ans: tput clear: clearing the screen tput command to clear the screen tput clear The execution of this vanishes whatever was typed and the prompt and cursor are positioned at the top-left corner of the screen. Exit: this command suspends the session $ exit login: The login: message confirms that the session has been terminated, thus making it available for the next user.

3. (a) explain internal and external commands with example 04 Ans: the commands having independent existence in the /bin directory (or /usr/bin), are called as an external command. For ex: ls command is an external command Echo isn’t an external command in the sense that, when we type echo, the shell won’t look in its PATH to locate it (even if it is there in /bin).Rather, it will execute it from its own set of built-in commands that are not stored as separate files.these built-in commands, of which echo is a member are known as internal commands.

3. (b) Explain the man documentation

06

ans: unix offers an on-line help facility in the man command.A man page is divided into a number of compulsory and optional sections.Every command doesn’t have all sections but the first three( NAME, SYNOPSIS and DESCRIPTION) are generally seen in all man pages.

4 NAME presents a one-line introduction to the command. SYNOPSIS shows the syntax used by the command and DESCRIPTION (often the largest section) provides a detailed description.the SYNOPSIS follows certain conventions and rules which every user must understand:  If a command argument is enclosed in rectangular brackets, then it is optional; otherwise, the argument is required.  The ellipsis (a set of three dots) implies that there can be more instances of the preceding word.  If there is a | character in any of these areas, it means that only one of the options shown on either side of the pipe can be used. All options used by the command are listed in the OPTIONS section.There’s a separate section EXIT STATUS which lists possible error conditions and their numeric representation. 4. Explain cal, echo, printf, bc, tty commands with example 10 Ans: cal: THE CALENDER The cal command is used to see the calender of any specific month or a complete year.the facility is totally accurate and takes into account the leap year adjustments that took place in the year $ Cal It displays the calender of the current month. The syntax also tells us that when cal is used with arguments, the month is optional but the year is not.To see the calender for the month of March 2003, you need two arguments: $ Cal 03 2003 March 2003 S

M

2 3 9 10 16 17 23 24 30 31

Tu W Th F S 1 4 5 6 7 8 11 12 13 14 15 18 19 20 21 22 25 26 27 28 29

Echo: displaying a message Echo is used in two ways  to display a message  to evaluate shell variables echo interprets certain strings known as escape sequences. An escape sequence is generally a two character-string beginning with a \ (backslash). $ echo “Enter filename:\c”

5 Enter filename: $ _ This is how echo is used in a shell script to accept input from the terminal. Escape sequence used by echo \a bell \b backspace \c no newline (cursor in same line) \f formfeed \n newline \r carriage return \t tab \v vertical tab \\ Backslash \0n ASCII character represented by the octal value n, where can’t exceed 0377(decimal value 255) printf: The command in its simplest form can be used in the same way as echo: $ Printf “No filename entered\n” No filename entered $ _ printf also accepts all escape sequences used by echo.printf uses many of the formats used by C’s printf function. %s %30s %d %6d %o %x %f

string as above but printed in a space 30 characters wide decimal integer as above but printed in a space 6 characters wide octal integer hexadecimal integer floating point number

bc: bc belongs to a family of commands that expect input from the keyboard when used without an rgument.key in the following arithmetic expression and then use [Ctrl-d] to quit bc: $ bc 12 + 5 17 [Ctrl-d] $ _ 12*12; 2^32 144 4294967296

; multiple calculation in the same line

To enable floating-point computation, the sacle have to be set to the number of digits of precision Scale=2 17/7

6 2.42 bc is quite useful in converting numbers from one base to another ibase=2 11001010 202

;output in decimal-base 10

The reverse is also possible obase=2 14 1110 bc also handles hexadecimal numbers obase=16 14 E tty: KNOWING YOUR TERMINAL This command tells the filename of the terminal you are using $tty /dev/pts/10 The terminal filename is 10 resident in the pts directory.the directory in turn is under the /dev directory. Tty is used in a shell script to control the behaviour of the script depending on the terminal it is invoked from. 5. Explain date, uname, sttty, who, script commands with options and example 10 Ans: date: we can display the current date with the date command, which shows the date and time to the nearest second: $ Date Tue Dec 10 18:52:26 IST 2002 We can print only month, using the format +%m: $ date +%m 12 Or the month name: $ date +%h Dec or you can combine them in one command:

7 $ date +”%h %m” Dec 12 Other format specifiers are d-the day of the month y-the last two digit of the year H, M and S-the hour, minute and second, respectively D-the date in the format mm/dd/yy T-the time in the format hh:mm:ss Uname: the command displays certain features of the operating system running on your machine. By default, it displays the name of the operating system: $ uname SunOS The Current Release and Implementation Name (-r and –s): the –r option is used to find the version of your operating system $ uname -r 5.8 The implementation name of this operating system can be obtained with the –s option $ uname -s SunOS The Machine Name (-n): if your machine is connected to a network, then it must have aname (called hostname).-n option tells the hostname $ uname -n mercury stty: this command displays and changes settings The –a option displays the current settings.the setting signifies [Ctrl-d] interrupts a program, [Ctrl-h] erase a character and [Ctrl-u] kills a character. Who:WHO ARE THE USERS? UNIX maintains an account of all user who are logged on to the system.the who command displays an informative listing of these users $ who root

console

Aug 1 07:51 (:0)

8 kumar sharma

pts/10 pts/6

Aug 1 07:56 (pc123.heavens.com) Aug 1 02:10 (pc125.heavens.com)

The first column shows the usernames (or user-id), the second column shows the device names of their respective terminals, the third, fourth and fifth columns show the date and time of logging in.the last column shows the machine name from where the user logged in. (-H) option prints the column header. To know the user who invoked the who command use the arguments am and I with who: $ who am i kumar pts/10 Aug 1 07:56 (pc123.heavens.com) script: RECORDING YOUR SESSION This command lets you record your login session in a file. $ script Script started, file is typescript $ _ The prompt returns and all your keystrokes that you noe enter here get recorded in the file typescript. Script –a Appends to it or uses a different log file. 6. (a) explain the different types of files supported in UNIX 06 Ans: the file is a container of information or a sequenceof charactersunix treats directories and devices as files as well. Files can be divided into three categories  ordinary file:an ordinary file itself can be divided into two types: .text file:a text file contains only printable characters.all C and Java program sources, shell and per1 scripts are text files. .binary file:a binary file contains both printable and unprintable characters that cover the entire ASCII range. Most UNIX commands are binary files, and the object code and excutables that you produce by compiling C programs are also binary files. Pictures, sounds and video files are binary files as well.  Directory file:a directory contains no data, but keeps some details of the files and subdirectories that it contains. A directory file contains an enty for every file and subdirectory that it houses.each entry has two components: . The filename .a unique identification number for the file or directory.  Device file:

9 Device filenames are generally found inside a single directory structure, /dev.it is advantageous to treat devices as files as some of the commands used to access an ordinary file also work with device files.the kernal identifies a device from its attributes and then uses them to operate the device. 6. (b) explain the UNIX file system tree

04

Ans: the file system in unix is a collection of all the related files (ordinary, directory and device files) organized in a hierarchical structure.the implicit feature of every unix file system is that there is a top, which serves as the reference point for all files.this top is called root and is represented by a / (frontslash).root is actually a directory. The root directory(/) has a number of subdirectories under it.these subdirectories, in turn , have more subdirectories and other files under them.every file apart from the root,must have a parent,and it should be possible to trace the ultimate parentage of a file to root.

7.explain the following commands with options and suitable example pwd,wc,cp,rm,more 10 Ans: pwd: pwd command tells you your current directory $ pwd /home/kumar pwd displays the absolute pathname. wc:wc command counts lines,words,and characters,depending on the options used. It takes one or more filenames as its arguments, and displays a four-columnar output. $ wc infile 3 20 103 infile wc counts 3 lines,20 words and 103 characters. wc offers three options to make a specific count.the –l option counts only the number of lines, while the –w and –c options counts words and characters respectively: $ wc -l infile 3 infile $ wc -w infile 20 infile $ wc -c infile 103 infile when used with multiple filenames, wc produce a line for each file,as well as a total count.

10 cp: the cp command copies a file or a group of files.it creates an exact image of the file on disk with a different name. the syntax requires at least two filename to be specified in the command line. When both are ordinary files,the first is copied to the second Cp chap01 until If the destination file(until) doesn’t exist, it will first be created before copying takes place. Interactive copying (-i): the –i option warns the user before overwriting the destination file. $ cp -i chap01 until cp:overwrite until (yes/no) ? y A y at this prompt overwrites the file. Copying directory structure (-R): it’s possible to copy an entire directory structure with the –R option. cp -R progs newprogs rm: files can be deleted with rm .it can delete more than file with a single invocation.the following command deletes the first three chapter of the book: rm chap01 chap02 chap03 Interactive deletion (-i): the –i option makes the command ask the user for confirmation before removing each file. Recursive deletion (-r or –R): with the –r (or –R) option, rm performs a tree walk – a through recursive search for all subdirectories and files within these subdirectories.at each step it deletes everything it finds. Forcing removal (-f): rm will prompt you for removal if a file is write-protected.the –f option overrides this minor protection also. More: the more command displays its output a page at a time. More chap01 The contents of chap01 is displayed on the screen,one page at a time.at the bottom of the screen,you’ll also see the filename and the percentage of the file that has been viewed. --more—(17%) to move forward one page,use f or spacebar & b to move back one page.10f can be used to scroll forward by 10 pages & 30b for scrolling back 30 pages. More has a repeat command, the dot that repeats the last command you used 8. (a) explain the use of ls command with –x,-F,-a & -r options 04

11 Ans: ls command is used to list the names of the files available in the directory ls with –x option is used to display filenames in multiple column $ ls -x 08_packets.html dept.lst

TOC.sh emp.lst

calender helpdir

cptodos.sh progs

ls with –F option is used to identify directories and executable files. ls with –a option lists all hidden files all with the other files. ls with –r option sorts filenames in reverse order. 8. (b) explain absolute pathname, relative pathname, argument and option? 04 Ans: If the first character of a pathname is a /, the file‘s location must be determined with respect to root. Such a pathname is called an absolute pathname. The relative pathname uses either the current or parent directory as reference and specifies the path relative to it.a relative pathnames uses one of these cryptic symbols: . (a single dot)- This represents the current directory. ..(two dots)-this represents the parent directory. Aruments are the additional words used along with the commands UNIX command use a filename as argument so the command can take input from the file. Options are special type of argument that’s mostly used with a – sign. For ex; ls -l note -l is an argument to ls by defination but it’s a special argument known as an option. 8. (c) Explain file command and home variable? 02 Ans: file command is used to determaine the type of file (regular, directory or device) $ file archive.zip archive.zip: ZIP archive File recognizes text files, and can distinguish between shell programs,c source and object code.it also identifies DOS executables,compressed files,PDF documents and even empty files. HOME variable: home directory is created by the system when a user account is opened.the shell variable HOME knows your current directory.the home directory is determined by the systemadministrator at the time of opening a user account.

Related Documents

Test Iq Oplossing Solution
November 2019 12
Apostila - Usp - Parte 1
November 2019 16
Solution 1
November 2019 17