Friday, October 15, 2010

UNIX INTERVIEW QUESTIONS PART4

83) What is the output of $> df -ivt filename
ANS:-Number of bytes = 512 * number of block occupied
84) what is the error in $> dfspace # disk free space The above command is in /etc
In order to execute we have to give $> /etc/dfspace
85) what is difference between pg and more command?
ANS:- pg permits to set the prompt whereas more doesnt.
86) what is the output of $> echo \\\
ANS:-$> echo \\\
> # continues on next line
\
$>
87) What does the following command do?
chmod 1754 filename
ANS:- 754 will set the file permissions and 1 is used to set sticky bit.
88) what is the output of $> ls -l | grep d*
ANS:- same as ls -l
89) State and explain about features of UNIX?
UNIX operating system originally was developed in 1969. This is an open source operating system developed by AT&T. It is widely used in work stations and servers. It is designed to be multi tasking, multi user and portable. UNIX has many several components packed together.

90) Explain about sh?
Sh is the command line interpreter and it is the primary user interface. This forms the programmable command line interpreter. After windows appeared it still retained the programmable characteristics.
91) Explain about system and user utilities?
There are two utilities they are system and user utilities. System utilities contain administrative tools such as mkfs, fsck, etc. Where as user utilities contain features such as passwd, kill, etc. It basically contains environment values.
92) Explain about document formatting?
UNIX systems were primarily used for typesetting systems and document formatting. Modern UNIX systems used packages such as Tex and Ghostscript. It uses some of the programs such as nroff, tbl, troff, refer, eqn and pic. Document formatting is very used because it forms the base of UNIX.
93) Explain about communication features in UNIX?
Early UNIX systems used inter user communication programs mail and write commands. They never contained a fully embedded inter user communication features. Systems with BSD included TCP/IP protocols.
94) Explain about chmod options filename?
This command allows you to change, write, read and execute permissions on your file. Changes can be done to the file system but at times you need to change permissions for the file systems. At times files should be executable for viewing the files.
95) Explain about gzip filename?
Gzip filename is used to compress the files so that those files take up less space. The size of the file actually gets reduced to half their size but they might also depend upon about the file size and nature of the file systems. Files using gzip file name end with .gz.
96) Explain about refer?
Refer was written in Bell Laboratories and it is implemented as a troff preprocessor. This program is used managing bibliographic references and it is used to cite them in troff documents. It is offered in most of the UNIX packages. It refers with text and reference file.
97) Explain about lpr filename?
This command is used to print a file. If you want to change the default print you can change the printer by using the P option. For double sided print you can use lpr-Pvalkyr-d. This is very useful command in UNIX present in many packages.
98) Explain about lprm job number?
This command is used to remove documents from the printer queue. The job number or the queue number can be found by using lpq. Printer name should be specified but this is not necessary if you want to use your default printer.
99) Brief about the command ff?
This command finds files present anywhere on the system. This command is used to find document location where you forgot the directory in which you kept the file but you do remember about the name. This command is not restricted in finding files it displays files and documents relevant to the name.
100) Brief about finger username?
This command is used to give information about the user; it gives out a profile about the user. This command is very useful for administrators as it gives the log information, email, current log information, etc. finger also displays information such as phone number and name when they use a file called .plan.
101) Explain about the command elm?
This command lets you to send email message from your system. This command is not the only one which sends email there are lots of other messenger systems which can facilitate the process of sending a mail. This command behaves differently on different machines.
102) Brief about the command kill PID?
This command ends the process to which it was assigned (ID). This command cannot be used in multi systems in the network. ID can be obtained by the command ps. This command ignores completely the state at which the process is it kills the process.
103) Explain about the command lynx?
This command helps you to browse web from an ordinary terminal. Text can be seen but not the pictures. URL can be assigned as an argument to the G command. Help section can be obtained by pressing H and Q makes the program to quit.
104) Brief about the command nn?
This command allows you to read the news. First you can read about the local news and then the remote news. "nnl” command makes or allows you to read local news and nnr command is used to read remote news. Manual and help information is available with many popular packages.
105) Brief about ftp hostname?
This command lets you download information, documents, etc from a remote ftp. First it is important to configure an FTP for the process to begin. Some of the important commands relevant to the usage of FTP are as follows get, put, mget, mput, etc. If you are planning to trANS:-fer files other than ASCII defined it is imperative to use binary mode.
106) What is shell scripting?
Shell scripting is used to program command line of an operating system. Shell Scripting is also used to program the shell which is the base for any operating system. Shell scripts often refer to programming UNIX. Shell scripting is mostly used to program operating systems of windows, UNIX, Apple, etc. Also this script is used by companies to develop their own operating system with their own features.
107) State the advantages of Shell scripting?
There are many advantages of shell scripting some of them are, one can develop their own operating system with relevant features best suited to their organization than to rely on costly operating systems. Software applications can be designed according to their platform.
108) What are the disadvantages of shell scripting?
There are many disadvantages of shell scripting they are
* Design flaws can destroy the entire process and could prove a costly error.
* Typing errors during the creation can delete the entire data as well as partition data.
* Initially process is slow but can be improved.
* Portbility between different operating system is a prime concern as it is very difficult to port scripts etc.
109) Explain about the slow execution speed of shells?
Major disadvantage of using shell scripting is slow execution of the scripts. This is because for every command a new process needs to be started. This slow down can be resolved by using pipeline and filter commands. A complex script takes much longer time than a normal script.
110) Give some situations where typing error can destroy a program?
There are many situations where typing errors can prove to be a real costly effort. For example a single extra space can convert the functionality of the program from deleting the sub directories to files deletion. cp, cn, cd all resemble the same but their actual functioning is different. Misdirected > can delete your data.
111) Explain about return code?
Return code is a common feature in shell programming. These return codes indicate whether a particular program or application has succeeded or failed during its process. && can be used in return code to indicate which application needs to be executed first.
112) What are the different variables present in Linux shell?
Variables can be defined by the programmer or developer they specify the location of a particular variable in the memory. There are two types of shells they are System variables and user defined variables. System variables are defined by the system and user defined variables are to be defined by the user (small letters).
113) Explain about GUI scripting?
Graphical user interface provided the much needed thrust for controlling a computer and its applications. This form of language simplified repetitive actions. Support for different applications mostly depends upon the operating system. These interact with menus, buttons, etc.
114) Explain about echo command?
Echo command is used to display the value of a variable. There are many different options give different outputs such as usage \c suppress a trailing line, \r returns a carriage line, -e enables interpretation, \r returns the carriage.
115) Explain about Stdin, Stdout and Stderr?
These are known as standard input, output and error. These are categorized as 0, 1 and 2. Each of these functions has a particular role and should accordingly functions for efficient output. Any mismatch among these three could result in a major failure of the shell.
116) Explain about sourcing commands?
Sourcing commands help you to execute the scripts within the scripts. For example sh command makes your program to run as a separate shell. .command makes your program to run within the shell. This is an important command for beginners and for special purposes.
117) Explain about debugging?
Shell can make your debugging process easier because it has lots of commands to perform the function. For example sh –ncommand helps you to perform debugging. It helps you to read the shell but not to execute it during the course. Similarly sh –x command helps you by displaying the arguments and functions as they are executed.
118) Explain about Login shell?
Login shell is very useful as it creates an environment which is very useful to create the default parameters. It consists of two files they are profile files and shell rc files. These files initialize the login and non login files. Environment variables are created by Login shell.
119) Explain about non-login shell files?
The non login shell files are initialized at the start and they are made to run to set up variables. Parameters and path can be set etc are some important functions. These files can be changed and also your own environment can be set. These functions are present in the root. It runs the profile each time you start the process.
120) Explain about shebang?
Shebang is nothing but a # sign followed by an exclamation. This is visible at the top of the script and it is immediately followed by an exclamation. To avoid repetitive work each time developers use shebang. After assigning the shebang work we pass info to the interpreter.
121) Explain about the Exit command?
Every program whether on UNIX or Linux should end at a certain point of time and successful completion of a program is denoted by the output 0. If the program gives an output other than 0 it defines that there has been some problem with the execution or termination of the problem. Whenever you are calling other function, exit command gets displayed.
122) Explore about Environment variables?
Environment variables are set at the login time and every shell that starts from this shell gets a copy of the variable. When we export the variable it changes from an shell variable to an environment variable and these variables are initiated at the start of the shell.
123) Explain about the case statement.
The case statement compares word to the patterns from top to bottom, and performs the commands associated with the first, and only the first, pattern that matches. The patterns are written using the shells pattern matching rules, slightly generalized.
124) Explain the basic forms of each loop?
There are three loops; for, while and until. For loop is by far the most commonly used form of loop. Basically like other programs it executes a given set of commands and instructions. While and until forms of loop use the exit status from a command based system. They control the execution of the commands in the body of the loop.
125) Describe about awk and sed?
The awk program processes this to report the changes in an easier to understand format. Sed output is always behind its input by one line; there is always a line of input that has been processed but not printed, and this would introduce an unwanted delay.
126) Explain about signal argument?
The sequence of commands is a single argument, so it must almost always be quoted. The signal numbers are small integers that identify the signal. For example, 2 is the signal generated by pressing the DEL key, and 1 is generated by hanging up the phone. Unless a program has taken explicit action to deal with signals, the signal will terminate it.
127) Explain about exec?
The exec is just for efficiency, the command would run just as well without it. Exec is a shell built-in that replaces the process running this shell by the named program, thereby saving one process- the shell that would normally wait for the program to complete. Exec could be used at the end of the enhanced cal program when it invokes /usr/bin/cal.
128) Explain about trap command
The trap command sequence must explicitly invoke exit, or the shell program will continue to execute after the interrupt. The command sequence will be read twice: once when the trap is set and once when it is invoked. Trap is used sometimes interactively, most often to prevent a program from being killed by the hangup signal.
129) Explain about sort command?
The sort command has an option –o to overwrite a file:
$ sort file1 -0 file2
Is equivalent to
$ sort file1 > file2
If file 1 and file 2 are the same file, redirection with > will truncate the input file before it is sorted. The –o option works correctly because the input is sorted and saved in a temporary file before the output file is created. Many other commands could also use a –o option.
130) Explain about the command overwrite?
Overwrite is committed to changing the original file. If the program providing input to overwrite gets an error, its output will be empty and overwrite will dutifully and reliably destroy the argument file. Overwrite could ask for conformation before replacing the file, but making overwrite interactive would negate its efficiency. Overwrite could check that its input is empty.
131) Explain about kill command?
The kill command only terminates processes specified by process-id when a specific background process needs to be killed, you must usually run ps to find the process-id and then re type it as an argument to kill. Killing process is dangerous and care must be taken to kill the right processes.
132) Explain about the shell variable IFS?
The shell variable IFS (internal field separator) is a string of characters that separate words in argument lists such as back quotes and for statements. Normally IFS contains a blank, a tab, and a new line, but we can change it to anything useful, such as just a newline.
133) Explain about the rules used in overwrite to preserve the arguments to the users command?
Some of the rules are
• $* and $@ expand into the arguments and are rescanned; blanks in arguments will result in multiple arguments.
• “$*” is a single word composed of all the arguments to the shell file joined together with spaces.
• “$@” is identical to the arguments received by the shell file: blanks in arguments are ignored and the result is a list of words identical to the original arguments.
134) Explain about @@@ lines?
@@@ Lines are counted (but not printed), and as long as the count is not greater than the desired version, the editing commands are passed through. Two ed commands are added after those from the history file: $d deletes the single @@@ line that sed left on the current version.
135) Explain about vis?
Vis that copied its standard input to its standard output, except that it makes all non printing characters visible by printing them as \nnn, where nnn is the octal value of the character. Vis is invaluable for detecting strange or unwanted characters that may have crept into files.
136) Is the function call to exit at the end of vis necessary?
The call to exit at the end of vis is not necessary to make the program work properly, but it ensures that any caller of the program will see a normal exit status from the program when it completes. An alternate way to return status is to leave main with return 0; the return value from main is the program’s exit status.
137) Explain about fgets?
Fgets (buf, size, fp) fetches the next line of input from fp, up to and including a newline, into buf, and adds a terminating \0; at most size-1 characters are copied. A Null value is returned at the end of the file.
138) Explain about efopen page?
The routine efopen encapsulates a vey common operation: try to open a file; if it`s not possible, print an error message and exit. To encourage error messages that identify the offending program, efopen refers to an external string program containing the name of the program, which is set in main.
139) Explain about yacc parser generator?
Yacc is a parser generator that is a program for converting a grammatical specification of a language like the one above into a parser that will parse statements in the language.
140) What exactly is UNIX?
UNIX is written in C and it is portable. It runs on a range of computers from microprocessors to the largest mainframes. The source code is available and written in high level language which makes it easy to adapt for a particular requirement.
141) Explain about the return key?
Return Key signifies the end of a line of input; it must be presses before the system will interpret the characters you have types. It serves as an example of control character return key can be typed by holding the control key and typing M.
142) Explain about DELETE and BREAK?
These keys have significant meaning sometimes DELETE is called as RUBOUT key. Break is sometimes called INTERRUPT. In most SYSTEMS the delete key stops a program immediately, without waiting for it to finish on some systems, Ctrl-C provides this service. Break is a synonym for DELETE or CTRL-C.
143) Explain about TYPE-ahead?
The kernel reads what you type as you type it, even if it’s busy with something else, so you can type as fast as you want, whenever you want, even when some command is printing at you. Your I/P characters will appear intermixed with the O/P characters but they will be stored away and interpreted in the correct order.
144) How to get a computer aided instruction?
Your system may have a command called learn which provides computer aided instruction on the file system and basic commands, the editor, document preparation and even “C” programming. IF $learn exists on your system, it will teach you what to do from there.
145) Explain about cat?
Cat is the simplest of all the printing commands. Cat prints the contents of all the files named by its arguments. The named file or files are catenated the terminal one after another with nothing between. You have to be quick with CTRL-S to stop O/P from cat before it flows off your screen.
146) How to search files for lines that match a pattern?
Grep command searches for files for lines which match a pattern.
E.g. g/regular expression/p.grep will also look for lines that don’t match the pattern, when the option-V is sued. grep can be used to search several files in that case it will prefix the file name.
147) Describe about the root file system?
The root file system has to be present for the system to execute /bin, /dev, and /etc are always kept on the root system because when the system starts only files in the root system are accessible and some files such as /bin/sh are needed to run at all. During the boot strap operation, all the file systems are checked for self consistency and attached to the root systems.
148) Explain about ZAP?
ZAP, which selectively kills processes, is another program. The main problem with that version is speed; it creates so many processes that it runs slowly, which is especially undesirable for a program that kills errant processes rewriting ZAP in C will make it faster.
149) Suppose that you are using a terminal in which the screen size is bigger than the normal 24 lines. If you want to use p and take full advantage of your terminal capabilities what choices are open to you?
You have to specify the screen size each time you use P. $P-36.
Also you could put a shell file in your bin.
$cat/usr/you/bin/p
Exec/usr/bin/p-36$*
$
Another solution is to modify p to use an environment variable that defines the properties of your terminal.
150) Explain abut low-level I/O?
The lowest of I/O is a direct entry into the O.S. your program reads or writes files in chunks of any convenient size. The kernel buffers your data into chunks that match the peripheral devices and schedule operations on the devices to optimize their performance over all users.
151) What are the special arrangements to make a terminal i/p and o/p?
When it is started by the shell, a program inherits three open files, with file descriptor 0, 1 and 2 called the standard i/p, the standard o/p, and the standard error. If the program reads “0” and writes descriptors 1 and 2, it can do I/O without opening files.
152) What function does “errno” do?
Sometimes it is nice to know what specific error occurred; for this purpose all system calls, when appropriate, leave an error number in an external integer called calls, when appropriate, leave an error number in an external integer called errno. By using errno, your program can, for example, determine whether an attempt to open a file failed because it did not exist or because you lacked permission to read it.
153) Describe the process of “spname”?
The operation of spname is straightforward enough, although there are a lot of boundary conditions to get right. Suppose the file name is /d1/d2/f. The basic ideas is to peel off the first component (/), then search that directory for a name close to the nest component (dl), then search that directory for something near d2, and so on, until a match has been found for each component. If at any stage there isn’t a plausible candidate in the directory, the search is abandoned.
154) Explain about fork?
Splitting is done by a system call named fork. Proc_id = fork (); splits the program into two copies, both of which continue to run. The only difference between the two is the value returned by fork, the process-id. Two copies of the program are made by the fork. In the child, the value returned by fork is zero, so it calls execlp, which does the command line and then dies. In the parent, fork returns non-zero so it skips the execlp.
155) What is the easiest way to store variables and explain?
The easiest way to store the values of the variables is in a 26-element array; the single-letter variable name can be used to index the array. But if the grammar is to process both variable names and values in the same stack, yacc has to be told that its stack contains a union of a double and an int, not just a double.
156)whats $# in a shell script?
ANS:- Count of arguments provided to a script
157.whats a $* in shell script?
ANS:- All arguments provided to the script as a single word
$? -Exit values of the last command
$$ -Process number of the current process
$! -Process number of the last background process
$n -The nth command line argument
158.Explain nohup with an example
ANS:- A UNIX command that allows a command to continue running even after the user is logged out. Basically it prevents the handler for the HUP(hangup) signal from executing. For example,
$nohup ls -lR >a_very_long_running_list_command.txt &
Note that & at the end. Execute this command-line without the
nohup prefixed and the job will get killed the moment you logout.
159.If $1 is the first parameter, whats $0?
ANS:- $0 (dollar zero) represents the command name. For example:
$my_script.sh param1
here $0 = my_script.sh and $1 = param1. Also, note that $# will be 1 (since there's only one command line parameter provided)
160.How do you see the return code of the last executed command?
ANS:- By checking the value of $? (Dollar Question mark)
161.Explain Cron with an example
ANS:- Cron is the UNIX scheduler component (or daemon as it is more appropriately called). It can be used to schedule tasks for run at a specific time or times. It is driven by a crontab file (usually
/etc/crontab).
162.Whats the "nice" command used for?
ANS:- It is used to change the priority of a running process. This utility is particularly useful in taming processes that demand higher CPU time with the scheduler.
163.Provide a regular expression for searching email addresses within a script file
ANS:- In it's simplest form, the regular expression would look like this:
[\w-]+@([\w-]+\.)+[\w-]+
164.Compare /etc/fstab and /etc/mtab
ANS:- Both are used by UNIX to maintain information on file systems and mounting-related information. The only difference is that
fstab contains the master list which is used by the mount command, whereas mtab contains a list of file systems that are currently mounted.
164) Explain about read slow?
One can call to read return 0 which signals the end of file life, if data is written on that file then a subsequent read will be able to find more bytes available. This observation is the basis of a program called readslow which continues to read its input, regardless of whether it got an end of file or not. Readslow is handy for watching the progress of the file.



Print this post

1 comment:

Anonymous said...

Hi

I read this post 2 times. It is very useful.

Pls try to keep posting.

Let me show other source that may be good for community.

Source: System interview questions

Best regards
Jonathan.