Sunday, January 12, 2014

101 UNIX INTERVIEW QUESTIONS

Hi Guys, I am writing this new post to put all interview questions which I came across during my interview with various companies. I believe that this post will be helpful to freshers as well as experience candidate in interview. These interview questions are mostly straight forward. I will come up with more tricky questions later. Please post your comments and suggestions ,which will make learning better for all. Some questions are having answer and some are not in below list of questions .You can post queries and doubts related with questions below, so I can answer them.Please let me know if you like the post, so you can see more post on Unix. 

Keep Sharing,Keep Learning guys :)

101 UNIX INTERVIEW QUESTIONS AND ANSWERS -

1.      How do you change ownership of a file?    chown
2.      How do you change the ownership of the files recursively?  Chown -R
3.      How do you change access of a file? Chmod 777 filename
4.      How do you remove duplicate entries from a file? Uniq filename
5.      How do you restrict the file size to a particular value? Ulimit size
6.      How to truncate a file (say you want only last 20 line of a file) tail –20 filename
7.      What are wild characters? These are the characters which gives special meaning to the shell. Ex: *, ?, ^ etc.
8.      What is sleep? What does it do?
     If you want some process to deactivate for a while then we can use sleep. It deactivates the process for the specified seconds.
9.      Regular expression to fit the US  phone number of format 999-999?
10.  How do you view the .a files? Dump –H filename.a
11.  What is a library? What is the extension  of a library file? 
      Library is a directory file where functions provided by unix for programmers are stored. Extension is .a.
12.  How to get information from a library file? Dump –H filename.a | grep
13.  What is the command used to output to both the console and the file?  Tee or tee with filename
14.  How to count the no.of files in the current directory? Wc
15.  Replace the blank characters with ~(tilde) in a file? Sed ‘s/ /~/’ filename
16.  How to print the contents of a file? Cat filename.
17.  How to list the process of a particular user?(And everything about ps)?  Ps –u <username>
18.  What is a pipe? What are named pipes?
Pipe concatenates two commands where the output of the first command acts as the input to the second command and so on.
Name pipes create inter process communication. It is a special file.
Named pipes are similar to pipes where two main files will be there as fields[0] and fields[1] which contains stream of files where the input one file destination stream act as the reading and the other file stream act as write.
19.  How to mail a file to a user? Mail username
20.  How to read the telephone number from a file(say the no. is in the format ### - ####)?
21.  How to execute a process with lower priority? Nice (options –n)                                                           
22.  How do you see the process consuming more CPU time? Top ps
23.What these operator  $, $$, # , | , ? , > , <, >> [], ` ,$?, $*    does??
24.  What is an awk?
25.  How to start a background process? What happens when you exit a shell before the process completes? By using &. It runs.
26.  Which is the first process that is started in Unix? Inittab
27.  How to get the values of control characters(say ctrl-c)?
28.  How to change the date and time of a file? Touch filename
29.  What is a semaphore?       
      A semaphore is a non-negative integer count and is generally used to co-ordinate access to resources.  The initial semaphore count is set to the number of free resources, then threads slowly increment and decrement the count as resources are added and removed. If the semaphore count drops to zero, which means no available resources, threads attempting to decrement the semaphore will block until the count is greater than zero.
30.  How do you remove the semaphores and shared memory? Semdestroy
31.  What are .b files? Batch files.
32.  How do you take a process already started as a foreground process to background? Give cntrl Z bg
33.  What is daemon? How do you write a daemon program? Daemon is a thread running all the time. It started only once. We can write by giving nohups.
34.  What is a cron daemon? Job scheduler
35.  How do you list the semaphores and shared memory?
      Semaphores are listed with ls –s. Shared memories are listed with ls –m
36.  How to connect to another terminal? rlogin or telnet.
37.  Difference between http and https?'
       http is a non secured protocol. https is secured protocol.
38.  What is SSL? Secured socket layer.
39.  What is the standard port no of HTTP? 80
40.  What is the standard port no of HTTPS?  443
41.  What are plugins? 
       Additional features to a browser/ server. You can call your own c++ code here.
42.  What is CGI? Common Gateway Interface.
43.  What is $?  ?
       ‘$?’ returns code from the previous executed command.
44.  Everything about sed and awk.
45.  All deamons, specially cron. How will you schedule your command using cron deamon? 
      Store the command in commandfile(cmdfile) .  crontab cmdfile.
46.  What are the first 3 fields in the cron tab file? Time (i.e. minutes hour dayof the month month of the year day of the week)
47.  What will cat<file1>file2 do give another command for it? 
      Copies the content of file1 to file2.            Cp file1 file2
48.  How do you check if the process running is taking a long time? Top
49.  What are background and foreground processes?
     Background processes are the one which runs even after exiting from the shell. Foreground processes are interactive.

50.  How do you choose a column from a file? Cut –c                                                                                                                                                                                                   
51.  What are the different types of shell? Bourne shell, Korn shell, C-shell, Bash-shell
52.  How do you inverse the occurrence of a regular expression? Grep –v
53.  How would you swap fields in a file with ‘ ‘(blank) as a delimeter? Awk f ‘{print $3 $2 }’ filename
54.  How do you compress a file? What is the syntax? What does pack –f do? 
      By giving the command called compress. Compress filename.
55.  What is nohup? What is syntad? Where does the output go, if you do not mention the output filename Nohup command. EX:- nohup sort emp.     If we are not redirecting the output of our background proces then the result is stored in nohup.out
56.  What is mail? How do you automate to send a mail after the end of a process? 
      Mail is a way to circulate memos and other written information to  your co-workers if you and they use networked computers.
57.  What is the internal value associated with the standard error device?  2
58.  How do you execute a command on a different machine without loging on to it? rlogin
59.  What does this meand: ${variable-value}?
60.  What does this meand: ${variable? Value}?
61.  How will you archive a file?  Tar cvf
62.  Which signal is sent to the kernel, when you kill a process?  Terminate.
63.  What is the difference between TCP/IP and OSI model?
OSI contains 7 layers
TCP/IP has 5 layers
64.  what is ARP (Address resolution protocol)?
65.  How do you find out which version of UNIX you are working with?  Uname –v
66.  What are environment variables? $HOME, $PATH                                                                   
67. What is the significance of $HOME and $PATH?
       Searches in all the specified set PATH for the given thing 
Takes to the root directory where you are logged in
68.  How do you display the environment variables? Env
69.  How will you know what version of a program is being picked up from among the paths described in the $PATH variable? 
70.  What is crontab? 
    It is a command which is used to carry out jobs everyday for years together without needing any prompting for us. This will excel over at and batch.
71.  What is inittab?   
      This file is  called when we start the machine which in turn calls the necessary processes or files.
72.  What is memory leakage?  
      Not releasing the memory or acquiring extra memory.
73.  How do you replace the occurrence of a string with  some other value using sed? 
      Sed ‘s/string/value/’ filename.
74.  What would you do if you want zero mapped to a and one mapped to b in a string? Tr[ab][01]
75.  What is archiving? Compressing
76.  What are signals?  Interrupts
77.  What are the five basic IPCs?
        Interprocess communications
        Pipe
        Fifo
78.  What is shared segment memory?
79.  What is  a web server?  Where browser requests can be met.
80.  How will you determine the path of travel between two hosts in a n/w?  tracert
81.  What are the seven layers of  TCP/IP?
82.  What is a mac address?
83.  Given a table containing several columns, write a shell program to sum up 2nd and 3rd column data.
84.  What is the difference between TCP/IP & UDP sockets? Write the series of steps showing the lifecycle of a socket.
85.  Which Shell your working and how do you find  your in which Shell?
86.  How do you see the process  consuming more CPU time?
87.  How do you find out which version of UNIX you are working with?
88.  How do you find out the Average Disk used by the all the files in the current directory?
89.  Difference between thread and process
90.  How to find process-> CPU consumption on SMP environment(multi processor environment)
91.  List various options of netstat
92.  How to find swap space consumption for each process
93.  Difference between vmstat and top
94.  Why threads are listed as a separate processes,  when we do ps –el
95.  What are the different types of shells that you have used?
96.  Where the major configuration files stored in UNIX ?
97.  Explain some of the shell scripts that you have written?
98.  Explain sed command?
99.  What is the regular expression for a number of length 15 digits?
100.  What is the regular expression for a String of length 15 which does not have digits.
101.    How to get no of records and no of fields in awk ?


                                            
                                                                COPYRIGHT © 2013 TECH BRAINS