Top 50 Unix Interview Questions

raju2006
June 13, 2016 0 Comments

Top 50 Unix Interview Questions

Q1 What is UNIX?

Answer: It is a portable operating system that is designed for both efficient multi-tasking and mult-user functions. Its portability allows it to run on different hardware platforms. It was written is C and lets user do processing and control under a shell.

 

Q2 What is the difference between Swapping and Paging?

Answer:

Swapping:
Whole process is moved from the swap device to the main memory for execution. Process size must be less than or equal to the available main memory. It is easier to implementation and overhead to the system. Swapping systems does not handle the memory more flexibly as compared to the paging systems.

Paging:
Only the required memory pages are moved to main memory from the swap device for execution. Process size does not matter. Gives the concept of the virtual memory. It provides greater flexibility in mapping the virtual address space into the physical memory of the machine. Allows more number of processes to fit in the main memory simultaneously. Allows the greater process size than the available physical memory. Demand paging systems handle the memory more flexibly.

 

Q3 What is Kernel?

Answer: Kernel is the UNIX operating system. It is the master program that controls the computer’s resources, allotting them to different users and to different tasks. However, the kernel doesn’t deal directly with a user. Instead, it starts up a separate, interactive program, called a shell, for each user when he/she logs on.

 

Q4 How the Swapper works?

Answer: The swapper is the only process that swaps the processes. The Swapper operates only in the Kernel mode and it does not uses System calls instead it uses internal Kernel functions for swapping. It is the archetype of all kernel process.

 

Q5 What is Shell?

Answer: A shell acts as an interface between the user and the system. As a command interpreter, the shell takes commands and sets them up for execution.

 

Q6 What is page fault.

Answer: Page Fault is reffered as the situation when the process addresses a page in working set of process but the process fails to locate the page in working set. And on page fault the kernal update the working set by reading the page from the secondary devices.

 

Q7 What are the key features of the Korn Shell?

Answer: – history mechanism with built-in editor that simulates emacs or vi
– built-in integer arithmetic
– string manipulation capabilities
– command aliasing
– arrays
– job control

 

Q8 What is Zombie process in UNIX? How do you find Zombie process in UNIX?

Answer: When a program forks and the child finishes before the parent, the kernel still keeps some of its information about the child in case the parent might need it for example, the parent may need to check the child’s exit status. To be able to get this information, the parent calls ‘wait()’; In the interval between the child terminating and the parent calling ‘wait()’, the child is said to be a ‘zombie’ (If you do ‘ps’, the child will have a ‘Z’ in its status field to indicate this.)

 

Q9 What is piping?

Answer: Piping, represented by the pipe character “|”, is used to combine two or more commands together. The output of the first command serves as input the next command, and so on.

 

Q10 What are shell variables?

Answer: Shell variables are a combination of a name ( identifier), and an assigned value, which exist within the shell. These variables may have default values, or whose values can be manually set using the appropriate assignment command. Examples of shell variable are PATH, TERM and HOME.

 

Q11 What is nohup in UNIX?

Answer: nohup is a special command which is used to run process in background, but it is slightly different than & which is normally used for putting a process in background. An UNIX process started with nohup will not stop even if the user who has stared log off from system. While background process started with & will stop as soon as user logoff.

 

Q12 Differentiate relative path from absolute path.

Answer: Relative path refers to the path relative to the current path. Absolute path, on the other hand, refers to the exact path as referenced from the root directory.

 

Q13 What is Bash Shell?

Answer: It is a free shell designed to work on the UNIX system. Being the default shell for most UNIX-based systems, it combines features that are available both in the C and Korn Shell.

 

Q14 What type of buffer are supported by unix.

Answer:

  1. Fully buffered.
  2. Line Buffered.
  3. Un Buffered.

 

Q15 What is IPC? What are the various schemes available?

Answer: The term IPC (Inter-Process Communication) describes various ways by which different process running on some operating system communicate between each other.

 

Q16 How do you know if a remote host is alive or not?

Answer: You can check these by using either ping or telnet command in UNIX. This question is most asked in various Unix command Interview because its most basic networking test anybody wants to do it.

 

Q17 Enumerate some of the most commonly used network commands in UNIX

Answer: – telnet – used for remote login
– finger – information gathering command
– ping – an echo request for testing connectivity
– su – user switching command
– ftp – file transfer protocol used for copying files

 

Q18 What is signals?

Answer: Signals are software interupts . Signal provide a way of handling asynchronous events: a user at a terminal typing the iterrupt key to stop a program or the next program in the pipeline termnating prematurely.

 

Q19 Is it possible to see information about a process while it is being executed?

Answer: Every process is uniquely identified by a process identifier. It is possible to view details and status regarding a process by using the ps command.

 

Q20 How do you set environment variable which will be accessible form sub shell?

Answer: By using export command, for example export count=1 will be available on all sub shell.

 

Q21 What is parsing?

Answer: Parsing is the process of breaking up of a command line into words. This is made possible by using delimiters and spaces. In the event that tabs or multiple spaces are part of the command, these are eventually replaced by a single space.

 

Q22 What is session?

Answer: A Session is a collection of one or more process group . A process establish a new session by calling setsid function. This function return process groupid ok.

 

Q23 What is ‘inode’?

Answer: All UNIX files have its description stored in a structure called ‘inode’. The inode contains info about the file-size, its location, time of last access, time of last modification, permission and so on. Directories are also represented as files and have an associated inode.

 

Q24 What does the swapping system do if it identifies the illegal page for swapping?

Answer: If the disk block descriptor does not contain any record of the faulted page, then this causes the attempted memory reference is invalid and the kernel sends a “Segmentation violation” signal to the offending process. This happens when the swapping system identifies any invalid memory reference.

 

Q25 Why is it that it is not advisable to use root as the default login?

Answer: The root account is very important, and with abusive usage, can easily lead to system damage. That’s because safeguards that normally apply to user accounts are not applicable to the root account.

 

Q26 What is the use of the tee command?

Answer: The tee command does two things: one is to get data from the standard input and send it to standard output; the second is that it redirects a copy of that input data into a file that was specified.

 

Q27 What are the process states in Unix?

Answer: As a process executes it changes state according to its circumstances. Unix processes have the following states:

  • Running : The process is either running or it is ready to run .
  • Waiting : The process is waiting for an event or for a resource.
  • Stopped : The process has been stopped, usually by receiving a signal.
  • Zombie : The process is dead but have not been removed from the process table.

 

Q28 What is shell scripting?

Answer: 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.

 

Q29 Explain about Login shell?

Answer: 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.

 

Q30 What is a daemon?

Answer: A daemon is a process that detaches itself from the terminal and runs, disconnected, in the background, waiting for requests and responding to them. It can also be defined as the background process that does not belong to a terminal session. Many system functions are commonly performed by daemons, including the send mail daemon, which handles mail, and the NNTP daemon, which handles USENET news. Many other daemons may exist.

 

Q31 Explain about GUI scripting?

Answer: 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.

 

Q32 What is ‘ps’ command for?

Answer: The ps command prints the process status for some or all of the running processes. The information given are the process identification number (PID),the amount of time that the process has taken to execute so far etc.

 

Q33 Brief about finger username?

Answer: 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.

 

Q34 Explain about the command elm?

Answer: 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.

 

Q35 Describe about awk and sed?

Answer: 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.

 

Q36 . How can a parent and child process communicate?

Answer: A parent and child can communicate through any of the normal inter-process communication schemes (pipes, sockets, message queues, shared memory), but also have some special ways to communicate that take advantage of their relationship as a parent and child. One of the most obvious is that the parent can get the exit status of the child.

 

Q37 How are devices represented in UNIX?

Answer: All devices are represented by files called special files that are located in/dev directory. Thus, device files and other files are named and accessed in the same way. A ‘regular file’ is just an ordinary data file in the disk.

 

Q38 Explain about kill command?

Answer: 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.

 

Q39 What is Shell Script and why it is required ?

Answer: A Shell Script is a text file that contains one or more commands. As a system administrator we often need to issue number of commands to accomplish the task, we can add these all commands together in a text file (Shell Script) to complete daily routine task.

 

Q40 What is the difference between a local variable and environment variable in Linux?

Answer: A local variable is the one in which the scope of the variable is only in the shell in which it is defined. An environment variable has scope in all the shells invoked by the shell in which it is defined.

 

Q41 Predict the output of the following program code

Answer:
main()
{
fork();
printf(“Hello World!”);
}

Answer: Hello World!Hello World!

Explanation: The fork creates a child that is a duplicate of the parent process. The child begins from the fork().All the statements after the call to fork() will be executed twice.(once by the parent process and other by child). The statement before fork() is executed only by the parent process.

 

Q42 What are the different modes when using vi editor?

Answer: There are 3 modes under vi:
– Command mode – this is the mode where you start in
– Edit mode – this is the mode that allows you to do text editing
– Ex mode – this is the mode wherein you interact with vi with instructions to process a file

 

Q43 What are the different type of variables used in a shell Script ?

Answer: In a shell script we can use two types of variables :

  • System defined variables
  • User defined variables

System defined variables are defined or created by Operating System(Linux) itself. These variables are generally defined in Capital Letters and can be viewed by “set” command.

 

Q44 What are links and symbolic links in UNIX file system?

Answer: A link is a second name (not a file) for a file. Links can be used to assign more than one name to a file, but cannot be used to assign a directory more than one name or link filenames on different computers.
Symbolic link ‘is’ a file that only contains the name of another file.Operation on the symbolic link is directed to the file pointed by the it.Both the limitations of links are eliminated in symbolic links.

 

Q45 What are various IDs associated with a process?

Answer: Unix identifies each process with a unique integer called ProcessID. The process that executes the request for creation of a process is called the ‘parent process’ whose PID is ‘Parent Process ID’. Every process is associated with a particular user called the ‘owner’ who has privileges over the process. The identification for the user is ‘UserID’. Owner is the user who executes the process.

 

Q46 What are environmental variables?

Answer: Environmental variables are global settings that control the shell’s function as well as that of other Linux programs. Another common term for environmental variables is global shell variables.

 

Q47 What Happens when you execute a program?

Answer: When you execute a program on your UNIX system, the system creates a special environment for that program. This environment contains everything needed for the system to run the program as if no other program were running on the system. Each process has process context, which is everything that is unique about the state of the program you are currently running. Every time you execute a program the UNIX system does a fork, which performs a series of operations to create a process context and then execute your program in that context.

 

Q48 An administrator you noticed from top command that an unidentified process is using up all CPU and memory. You suspects that is a user’s process that has run away. How should you fix this ?

Ans. The process should be immediately killed before it consumes so many resources that the server cannot run properly, and therefore crash.

 

Q49 What are hard links?

Answer: Hard links point directly to the physical file on disk, and not on the path name. This means that if you rename or move the original file, the link will not break, since the link is for the file itself, not the path where the file is located.

 

Q50 What are daemons?

Answer: Daemons are services that provide several functions that may not be available under the base operating system. Its main task is to listen for service request and at the same time to act on these requests. After the service is done, it is then disconnected and waits for further requests.

 

Q51 What is the use of continue command in shell scripting ?

Answer: The continue command is identical to break command except it causes the present iteration of the loop to exit, instead of the entire loop. Continue command is useful in some scenarios where error has occurred but we still want to execute the next commands of the loop.

 

Q52 How to find all the .c and .h files in Linux?
Answer: $ find . -name “*.[ch]”

 

Q53 What is the use of break command ?

Answer: The break command is a simple way to escape out of a loop in progress. We can use the break command to exit out from any loop, including while and until loops.
**********ALL THE BEST********