May 7, 2009

Linux Interview Questions-3

What is Linux and why is it so popular?

Answer
Linux is an operating system that uses UNIX like Operating system. However, unlike UNIX, Linux is an open source and free software. Linux was originally created by Linus Torvalds and commonly used in servers.

Popularity of Linux is because of the following reasons

  • It is free and open source. We can download Linux for free and customize it as per our needs.
  • It is very robust and adaptable.
  • Immense amount of libraries and utilities


What is LILO?

Answer
LILO is Linux Loader is a boot loader for Linux. It is used to load Linux into the memory and start the Operating system. LILO can be configured to boot other operating systems as well. LILO is customizable, which means that if the default configuration is not correct, it can be changed. Config file for LILO is lilo.conf


What is the difference between home directory and working directory?

Answer
Home directory is the default working directory when a user logs in. On the other hand, working directory is the user’s current directory. Working directory can be changed. It can be changed using cd command.

Home directory in Linux contains user’s personal data, configuration files, settings of a software etc. The content of home directory is private and the user has a complete control of it.


What is the difference between internal and external commands?

Answer
Internal commands are commands that are already loaded in the system. They can be executed any time and are independent. On the other hand, external commands are loaded when the user requests for them. Internal commands don’t require a separate process to execute them. External commands will have an individual process. Internal commands are a part of the shell while external commands require a Path. If the files for the command are not present in the path, the external command won’t execute.


Explain the difference between a static library and a dynamic library?

Answer
Static libraries are loaded when the program is compiled and dynamically-linked libraries are loaded in while the program is running. Dynamic libraries save the RAM space as against the static library because linking to static libraries includes the actual code for the library function(s)/procedure(s) with the executable. DLL code is kept at one location and is usually shared among all the processes that use the DLL.


What is LD_LIBRARY_PATH?

Answer
LD_LIBRARY_PATH is an environment variable. It is used for debugging a new library or a non standard library. It is also used for which directories to search. Path to search for directories needs to given. The variable can be set by using setenv—LD_LIBRARY_PATH--$PATH

What is the file server in Linux server?

Answer
File server is used for file sharing. It enables the processes required fro sharing. All the files can be stored at a centralized location. Linux uses Samba to view the files on the server. Files on this server are backed up on a regular basis. Rights can be also assigned for the files on a file server.


What is NFS? What is its purpose?

Answer
NFS is Network File system. It is a file system used for sharing of files over a network. Other resources like printers and storage devices can also be shared. This means that using NFS files can be accessed remotely. Nfs command in linux can be used to achieve this.

Purpose of NFS:

  • NFS can be used for sharing of files remotely.
  • Data can be stored on a single machine and still remain accessible to others over the network.
  • Reduction of the number of removable media drives throughout the network since they can be shared.


How do I send email with linux?

Answer
Email can be sent in Linux using the mail command.

Mail [options] [users]

Options include: -s for subject, -c for carbon copy, -b for blind carbon copy

E.g. mail user_name –s “hello”


Explain RPM (Red Hat Package Manager) features.

Answer
RPM is a package managing system (collection of tools to manage software packages).

Features:

  • RPM can verify software packages.
  • RPM can be served as a powerful search engine to search for software’s.
  • Components, software’s etc can be upgraded using RPM without having to reinstall them
  • Installing, reinstalling can be done with ease using RPM
  • During updates RPM handles configuration files carefully, so that the customization is not lost.


What is Kernel? Explain the task it performs.

Answer
Kernel is used in UNIX like systems and is considered to be the heart of the operating system. It is responsible for communication between hardware and software components. It is primarily used for managing the systems resources as well.

Kernel Activities:

  • The Kernel task manager allows tasks to run concurrently.
  • Managing the computer resources: Kernel allows the other programs to run and use the resources. Resources include i/o devices, CPU, memory.
  • Kernel is responsible for Process management. It allows multiple processes to run simultaneously allowing user to multitask.
  • Kernel has an access to the systems memory and allows the processes to access the memory when required.
  • Processes may also need to access the devices attached to the system. Kernel assists the processes in doing so.
  • For the processes to access and make use of these services, system calls are used.


What is Linux Shell? What is Shell Script?

Answer
Linux shell is a user interface used for executing the commands. Shell is a program the user uses for executing the commands. In UNIX, any program can be the users shell. Shell categories in Linux are:

Bourne shell compatible, C shell compatible, nontraditional, and historical.

A shell script, as the name suggests, is a script written for the shell. Script here means a programming language used to control the application. The shell script allows different commands entered in the shell to be executed. Shell script is easy to debug, quicker as compared to writing big programs. However the execution speed is slow because it launches a new process for every shell command executed. Examples of commands are cp, cn, cd.


What are Pipes? Explain use of pipes.

Answer
A pipe is a chain of processes so that output of one process (stdout) is fed an input (stdin) to another. UNIX shell has a special syntax for creation of pipelines. The commands are written in sequence separated by |. Different filters are used for Pipes like AWK, GREP.

e.g. sort file | lpr ( sort the file and send it to printer)

Uses of Pipe

  • Several powerful functions can be in a single statement
  • Streams of processes can be redirected to user specified locations using >


Explain trap command; shift Command, getopts command of linux.

Answer
Trap command: controls the action to be taken by the shell when a signal is received.

Trap [OPTIONS] [ [arg] signspec..]

Arg is the action to be taken or executed on receiving a signal specified in signspec.

e.g. trap “rm $FILE; exit” // exit (signal) and remove file (action)

Shift Command: Using shift command, command line arguments can be accessed. The command causes the positional parameters shift to the left. Shift [n] where n defaults to 1. It is useful when several parameters need to be tested.

Getopts command: this command is used to parse arguments passed. It examines the next command line argument and determines whether it is a valid option

Getopts {optstring} {variable1}. Here, optsring contains letters to be recognized if a letter is followed by a colon, an argument should be specified. E.g (whether the argument begins with a minus sign and is followed by any single letter contained inside options ) If not, diagnostic messages are shown. It is usually executed inside a loop.

What Stateless Linux server? What feature it offers?

Answer
A stateless Linux server is a centralized server in which no state exists on the single workstations. There may be scenarios when a state of a partilcuar system is meaningful (A snap shot is taken then) and the user wants all the other machines to be in that state. This is where the stateless Linux server comes into picture.

Features:

  • It stores the prototypes of every machine
  • It stores snapshots taken for those systems
  • It stores home directories for those systems
  • Uses LDAP containing information of all systems to assist in finding out which snapshot (of state) should be running on which system.


What does nslookup do? Explain its two modes.

Answer
Nslookup is used to find details related to a Domain name server. Details like IP addresses of a machine, MX records, servers etc. It sends a domain name query packet to the corresponding DNS.

Nslookup has two modes. Interactive and non interactive. Interactive mode allows the user to interact by querying information about different hosts and domains.

Non interactive mode is used to fetch information about the specified host or domain.

Interactive mode:

Nslookup [options] [server]


What is Bash Shell?

Answer
Bash is a free shell for UNIX. It is the default shell for most UNIX systems. It has a combination of the C and Korn shell features. Bash shell is not portable. any Bash-specific feature will not function on a system using the Bourne shell or one of its replacements, unless bash is installed as a secondary shell and the script begins with #!/bin/bash. It supports regular and expressions. When bash script starts, it executes commands of different scripts.


Explain some Network-Monitoring Tools in Linux: ping, traceroute, tcpdump, ntop

Answer
Network monitoring tools are used to monitor the network, systems present on the network, traffic etc.

Ping: Ping command is used to check if the system is in the network or not. To check if the host is operating.

e.g. ping ip_address

When the command is executed, it returns a detailed summary of the host. Packets sent, received, lost by estimating the round trip time.

Traceroute: the command is used to trace the path taken by the packet across a network. Tracing the path here means finding out the hosts visited by the packet to reach its destination. This information is useful in debugging. Roundtrip time in ms is shown for every visit to a host.

Tcpdump: commonly used to monitor network traffic. Tcdump captures and displays packet headers and matching them against criteria or all. It interprets Boolean operators and accepts host names, ip address, network names as arguments.

Ntop: Network top shows the network usage. It displays summary of network usage by machines on the network in a format as of UNIX top utility. It can also be run in web mode, which allows the display to be browsed with a web browser. It can display network traffic statistics, identify host etc. Interfaces are available to view such information.


How does the linux file system work?

Answer
Linux file structure is a tree like structure. It starts from the root directory, represented by '/', and then expands into sub-directories. All the partitions are under the root directory. If a partition is mounted (The mount point defines the place of a particular data set in the file system) anywhere apart from a “device”, the system is not aware of the existence of that partition or device. Directories that are only one level below the root directory are often preceded by a slash, to indicate their position.

Explain file system of linux. The root "/" filesystem, /usr filesystem, /var filesystem, /home filesystem, /proc filesystem.

Answer
Root "/" file system:
The kernel needs a root file system to mount at start up. The root file system is generally small and should not be changed often as it may interrupt in booting. The root directory usually does not have the critical files. Instead sub directories are created. E.g. /bin (commands needed during bootup), /etc (config files) , /lib(shared libraries).

/usr filesystem : this file system is generally large as it contains the executable files to be shared amongst different machines. Files are usually the ones installed while installing Linux. This makes it possible to update the system from a new version of the distribution, or even a completely new distribution, without having to install all programs again. Sub directories include /bin, /include, /lib, /local (for local executables)

/var filesystem : this file system is specific to local systems. It is called as var because the data keeps changing. The sub directories include /cache/man (A cache for man pages), /games (any variable data belong to games), /lib (files that change), /log (log from different programs), /tmp (for temporary files)

/home filesystem: - this file system differs from host to host. User specific configuration files for applications are stored in the user's home directory in a file. UNIX creates directories for all users directory. E.g /home/my_name. Once the user is logged in ; he is placed in his home directory.

/proc filesystem : this file system does not exist on the hard disk. It is created by the kernel in its memory to provide information about the system. This information is usually about the processes. Contains a hierarchy of special files which represent the current state of the kernel .Few of the Directories include /1 (directory with information about process num 1, where 1 is the identification number), /cpuinfo (information about cpu), /devices (information about devices installed), /filesystem (file systems configured), /net (information about network protocols), /mem (memory usage)


What are the process states in Linux?

Answer
Process states in Linux:

  • Running: Process is either running or ready to run
  • Interruptible: a Blocked state of a process and waiting for an event or signal from another process
  • Uninterruptible: a blocked state. Process waits for a hardware condition and cannot handle any signal
  • Stopped: Process is stopped or halted and can be restarted by some other process
  • Zombie: process terminated, but information is still there in the process table.


What is a zombie?

Answer
Zombie is a process state when the child dies before the parent process. In this case the structural information of the process is still in the process table. Since this process is not alive, it cannot react to signals. Zombie state can finish when the parent dies. All resources of the zombie state process are cleared by the kernel


Explain each system calls used for process management in linux.

Answer
System calls used for Process management:

  • Fork () :- Used to create a new process
  • Exec() :- Execute a new program
  • Wait():- wait until the process finishes execution
  • Exit():- Exit from the process
  • Getpid():- get the unique process id of the process
  • Getppid():- get the parent process unique id
  • Nice():- to bias the existing property of process

No comments:

Post a Comment