Saturday, September 17, 2011

Linux Admin Related Questions & Answers

What is Linux and why is it so popular?

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 reason

●     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?

LILO stands for Linux Loader which is a bootstrap program. LILO is a code snippet which loads PC BIOS into the main memory at the time of starting the computer system. LILO handles the following tasks:

-Locating Linux kernel
-Identifying other supporting programs and loading them in the memory
-Staring Kernel

The selection of various kernel images and boot routines is supported by LILO. For this reason, LILO is known as boot manager.

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 LILO?

LILO stands for Linux Loader which is a bootstrap program. LILO is a code snippet which loads PC BIOS into the main memory at the time of starting the computer system. LILO handles the following tasks:

-Locating Linux kernel
-Identifying other supporting programs and loading them in the memory
-Staring Kernel

The selection of various kernel images and boot routines is supported by LILO. For this reason, LILO is known as boot manager.

What is the difference between internal and external commands?

The commands that are directly executed by the shell are known as internal commands. No separate process is there to run these commands.

The commands that are executed by the kernel are knows as external commands. Each command has its unique process id.

What is the file server in Linux server?

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?

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?

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.

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.

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?

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.

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 Pipes

●     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.

trap command is used to catch a signal that is sent to a process. An action is taken based on the signal by using the action which is defined in the trap command instead of taking the default effect on the process.

Example:

$ trap “echo ‘interrupt signal received’ “ INT.

shift command is used to replace the parameters that were sent from command line. For example

$ shift will replace $1 by $2

getopts command is used for the purpose of parsing positional parameters.

What Stateless Linux server? What feature it offers?


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.

Nslookup is a program used to find information about internet Domain Name server.

The two modes of nslookup are: Interactive and non-interactive.

Using ‘interactive mode’ user can query the name servers for the information pertaining to hosts and domains.

Using ‘non-interactive mode’ the user can just print the name and requested information of a host.

What is Bash Shell?

Bash stands for "Bourne Again Shell”. A shell is the user interface. Bash is more convenient shell for users among others. The scripts written in Bash are portable among machines, distributions and even operating systems.

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

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.

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)

How does the Linux file system work?

At the time of installation of Linux, a file system is assigned and persists in the hard disk. This file system structure resembles a tree.
A file can be a list of names and numbers or executable programs. Linux treats every program as a file. Linux treats directories and computer components also as files.
A file could be a list of names and numbers, a cheesecake recipe, or an executable program. But under Linux, everything is a file. In addition to data and executable files, Linux treats directories and even the various components of your computer as files. It could be a keyboard, console, and printer, RAM or ROM. These are referred as special files known as devices. These files are available in /dev directory. Linux performs the communication with these devices by simply reading from or writing to these special files.

What are the process states in Linux?

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?

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.

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 

Describe initial process sequence while the system boots up.

1) BIOS
2) Master Boot Record (MBR)
3) LILO or GRUB
4) Kernel
5) init
6) Run Levels

1) BIOS: Loads the boot sector from the storage media. The order of booting can be changed using BIOS.

2) (DOS) Master Boot Record (MBR): DOS option includes MS-DOS, Windows. The first 512 bytes off the disk i.e., /dev/had will be executed by BIOS. The standard MBR looks for the primary partition i.e., /dev.hda1-4 which is marked bootable.

3) LILO: The kernel image is to be loaded as it does not understand the file system code. The kernel image is persisted as raw disk offsets using BIOS routines to load the sequence. Typically the menu code is available in /boot/boot.b and prompts for the partition or kernel for image (Linux) or other (DOS) to load first 512 bytes of the partition.

4) Kernel: Initializes devices, loads ‘initrd’ optionally, mounts root file system that is specified by lilo or loadin with root=parameter. Runs /sbin/init which has the process number 1(PID = 1) and prints the version number.

5) /sbin/init: Reads the /etc/inittab. Executes the boot scripts debian in turn runs /etc/rcS.d/S* scripts, runs the programs available in /etc/inittab.

6) Run Levels: The default level is defined in /etc/inittab. Ex: id: 3: initdefault: The other levels are:

0 halt
1 single user
2 Full Multi-User modes (default)
3-5 Same as 2
6 Reboot 

What is a shell? What are shell variables?

A shell us an interface to the user of any operating system. The users instruct an operation to the computer by typing commands as text for the execution.

Shell variables are special variables. They are name and value pairs created and maintained by the concerned shell. For example: PATH, HOME, MAIL, TERM etc. 

Explain how the inode maps to data block of a file.

There are 13 block addresses in inode. The file descriptions – type of file, access rights, and owners, time stamps of the files, size, and pointers to data blocks – are contained in each inode.

The first 10 block addresses are called direct block addresses which are the data blocks for the first 10 in the file.

The 11th, 12th and 13th addresses are pointed to a one-level index block and two-level index block and three-level index blocks respectively.

Describe how a parent and child process communicates each other.

The inter communication between a child process and a parent process can be done through normal communication schemes such as pipes, sockets, message queues, shared memories. There are special ways to inter communicate which has advantage of the relationships.

One of the most obvious advantages is that the exit status of the child process can be obtained by the parent process.

By communicating with unnamed pipes, the creation on pipe should be done before the creation of child. This process is called forking. Soon after forking, the parent properties will be inherited by child, also the pipe. The communication between parent and child is done with this pipe

What is a Daemon?
Daemon is the short form for Disk and Execution Monitor. A daemon is a background process which answers requests for services in a long-running mode. In UNIX, the names of daemons are end with‘d’ conventionally. Some of the daemons are “inetd, httpd, nfsd, sshd, named, and lpd “.

What is 'ps' command for?

The shortage for “process status” is ps. This command is used to display the currently running processes on Linux/Unix systems. It is like task manager in Windows. To stop the currently running process for the purpose of gaining the system speed, and find out the processes that are running on the remote system, the ps command is a tool. Stopping of a process can be done by kill command.

How the Swapper works?

Moving the information from fast access memory and slow access memory and vice versa is known as swapping. The physical RAM is divided into chunks of memory known as pages. A page of memory is copied to the preconfigured space on the hard disk, for the purpose of freeing up that page of memory.

To perform swapping, the commands swapon and swapoff are used in linux/unix. The swapon is to enable the swapping and the swapoff is to disable swapping.

What is ex and vi? Explain their purposes.

ex – the line editor mode of ‘vi’ editor. It allows to

      - write LISP programs
      - list all the files saved as the result of an editor or system crash
      -prevent the accidental overwriting of files
      -encrypt and decrypt the files

vi – screen oriented visual editor. It performs almost all the operations that are supported by ex. It has the additional features to edit, save lines and files. It provides the cursor movement options, editing options. Useful to write shell scripting in Linux/Unix

What is kill()? Explain its possible return values.

kill() is a system call which stops a process. The return values of kill() are:

-      0 – Process is existing with the given PID, and signals can be sent to it.
-      -1 – The ‘errno == ESRCH’ is true. This implies the non-existence of a process with a given PID or causing the denial of system by security enhancements for its existence.
-      -1 – The ‘errno == EPERM’ is true. This implies that the kill proess will not be allowed by the system with the given PID, which implies that the process exists or the enhancements are present by draconian security.
-      -1 – At times some other values returned by ‘errno’.

Explain the steps that a shell follows while processing a command.

The sequence of executing commands by shell are as follows:

Parsing: The command is broke into words, by using the spaces as delimiters unless quoted. The tabs are replaced by a single space.

Evaluation of a variable: The words with $ as preceding character will be evaluted unless quoted.

Command Substitution: The commands surrounded by backquotes will be executed by the shell. Later these will be replaced into standard output of the command into command line.

Wild card interpretation: Finally, the shell identifies all the wild cards(?,*) in the command line and replaces the wild card with sorted list of file names which maches the pattern.

PATH evaluation: Ultimately shell looks for the PATH variable for the purpose of determining the sequence of directories to search for the files or commands.

What is the use of ‘grep’ command? Provide an example

Grep stands for regular expression. ‘grep’ command is used to find the patterns in a text file provided by the user. It returns true if the pattern is found in the file, otherwise false.

Examples:

grep Lin file1 file2 file3
searches the files file1, file2, file3 for the lines which contains the string Lin.

grep ‘Linux learning is great ’ file1 file2 file3
searches the files file1, file2, file3 for the lines which contains the string ‘Linux learning is great’.

grep -c Linux operatinsystems
displays only the number of times that the pattern is matched in the file but not the lines.

grep -r 'Linus Torvalds' *
searches for the files in current and all the sub directories for the pattern (Linus Torvalds).


Difference between cat and more command.

The file contents are displayed by ‘cat’ command. The contents will scroll off the screeen, when the file contents are more than one screen page.

The file contents are displayed page by page with the use of ‘more’ command.

Examples

cat linux.txt
displays the contents of the file linux.txt
ls –l | more

displays the file and directory names. Halts once the screen page is full and prompts to press a key to continue


Linux - What is ‘du’ command? What is its use? - June 09, 2009 at 21:00 pm by Vidya Sagar

What is ‘du’ command? What is its use?

The du (disk usage) command is used to report the size of directory trees. These include the contents and the size of all files.

It is useful to use du command for the purpose of tracking down the space hogs. A hog is an excessive or large space occupied by the files and directories on a secondary storage media.

The command du is mostly employed by the system administrators. They use du as a supplement to the automated monitoring system programs which help to prevent the key directories and partitions from being full.

Explain the various prompts that are available in a UNIX system.

UNIX supports 4 prompts:
PS1: default prompt
PS2: for the purpose of multi-line input
PS3: for printing the select command
PS4: for printing before the output if –x is set.

Describe how the kernel differentiates device files and ordinary files.

There are 2 device files. They are character device file and block device file. To distinguish these two, specify b – for block device file and c – for character device file in the inode structure of the file.

An ordinary file does not require these fields.

Explain how to switch to a super user status to gain privileges.

The command ?su? is used to get super user status. The operating system prompts for the password and when valid, the user can gain the super user / administrator privileges.