Saturday 28 May 2011


LINUX OPERATING SYSTEM

Q: What is Linux?
Answer:
Linux is an operating system. It is the software on a computer that enables applications and the computer operator to access the devices on the computer to perform desired functions. The operating system relays instructions from an application to, for instance, the computer's processor. The processor performs the instructed task, then sends the results back to the application via the operating system.
Linux is a Unix-like operating system that was designed to provide personal computer users a free or very low-cost operating system comparable to traditional and usually more expensive Unix systems. Linux has a reputation as a very efficient and fast-performing system. Linux's kernel was developed by Linus Torvalds at the University of Helsinki in Finland. To complete the operating system, Torvalds and other team members made use of system components developed by members of the Free Software Foundation for the GNU Project.
Q: How Linux is Different From Other Operating System?
Answer:
Linux is distinguished from many popular operating systems in three important ways.
·         Linux is a cross-platform operating system that runs on many computer models. In comparison, Windows 95 and Windows 98 run only on CPUs having the Intel architecture. Windows NT runs only on CPUs having the Intel architecture or the DEC Alpha.

·         Linux is free, in two senses. First, we may pay nothing to obtain and use Linux. On the other hand, you may choose to purchase Linux from a vendor who bundles Linux with special documentation or applications, or who provides technical support. Linux is free or nearly free in an economic sense. Second, and more important, Linux and many Linux applications are                                             distributed in source form. This makes it possible for us and others to modify or   improve them.We are not free to do   this with most operating systems, which are   distributed in binary form.

·         Linux has attractive features and performance. Free access to Linux source code lets programmers around the world implement new features, and tweak Linux to improve its performance and reliability. The best of these features and tweaks are incorporated in the standard Linux kernel or made available as kernel patches or applications.

Q: What is Shell ?
Answer:
The command interpreter is the interface between the user and the operating system, hence the name "shell".
The shell therefore acts as an intermediary between the operating system and the user thanks to command lines that are entered by the latter. Its role consists in reading the command line, interpreting its meaning, carry out the command, and then return the result via the outputs.
The shell is an executable file responsible for interpreting the commands, transmitting them to the system, and returning the result. Ther are several shells, the most common being sh (called "Bourne shell"), bash ("Bourne again shell"), csh ("C Shell"), Tcsh ("Tenex C shell"), ksh ("Korn shell"),and zsh ("Zero shell"). Their name generally matches the name of the executable.

Linux Is Portable:
A portable operating system is one that can run on many different machines. More than 95 percent of the Linux operating system is written in the C programming language, and C is portable because it is written in a higher-level, machine-independent language. It can be adapted (ported) to different machines and can meet special requirements. Therefore Linux is portable

Q: What are the features of Linux ?

Answer:

Linux has the following features as an outstanding operating system which is strong in security and networking.

Multitasking: Several programs can run at the same time.

Multiuser: Several users can logon to the same machine at the same time There is no need to have separate user licenses.

Multiplatform: Linux runs on many different CPUs, that means it supports multiprocessor machine.


Multithreading: Linux has native kernel support for multiple independent threads of control within a single process memory space.

Crash proof: Linux has memory protection between processes, so that one program can't bring the whole system down.

Demand loads executables: Linux only reads from those parts of a program that are actually used on the disk.

Shared copy-on-write pages among executables: This means that multiple processes can use the same memory to run in. When one tries to write to that memory, that page is copied somewhere else. Copy-on-write has two benefits: increasing speed and decreasing memory use.

Free and Open source code for all: All source code of Linux is available,including the whole kernel and all drivers, the development tools and all user programs; also, all of it is freely distributable.

•Linux has a unified memory pool for user programs and disk cache, so that all free memory can be used for caching, and the cache can be reduced when running large programs.

• Linux is mostly compatible with POSIX, System V, and BSD at the source level.

• Linux has CD-ROM file system which reads all standard formats of CD-ROMs.

• Linux performs well with TCP/IP networking, including ftp, telnet, NFS, etc.


Q: What are standard input and standard output?

Answer: 

Most Linux commands read input, such as a file or another attribute for the command, and write output. By default, input is being given with the keyboard, and output is displayed on our screen. Our keyboard is our "standard input" (stdin) device, and the screen or a particular terminal window is the "standard output"
(stdout) device.


Q: What is vim editor?

Answer: 

Vim is a highly configurable text editor built to enable efficient text editing..It is an improved version of the vi editor distributed with most UNIX system. Vim is free and open source software. Vim editor consist of many features designed to be helpful in editing program source code. Vim is a cross-platform supporting many other platforms. Lastly Vim is the most popular editor.

Q: What are the three modes of vi editor?
Answer:
The vi editor has three modes, command mode, insert mode and command line mode.
  1. Command mode: Letters or sequences of letters interactively command vi. Commands are case sensitive. The ESC key can end a command.
  2. Insert mode: Text is inserted. The ESC key ends insert mode and returns us to command mode. One can enter insert mode with the "i" (insert), "a" (insert after), "A" (insert at end of line), "o" (open new line after current line) or "O" (Open line above current line) commands.
  3. Command line mode: One enters this mode by typing ":" which puts the command line entry at the foot of the screen.

Q: What are the features of vim?
Answer:
Ø  One extremely convenient feature of vim is its ability to fold text. With this feature, we can make parts of a text file disappear, without actually removing it.
Ø  Another neat feature here is that if we make changes to the fold and add or remove text, vim still remembers the start and end markers and will fold it accordingly.
Ø  Another feature on vim is its abbreviation feature. With it, we can create abbreviations for text. By typing this in command mode:
:abbr ap Apache Web Server.
 
 
Q: How Does The Linux File System Work?

Answer:

In 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. When Linux is installed, a file system is carved out of a chunk of hard disk and formatted so that Linux can use it. A hierarchical (treelike) structure for storing files imposes some order on the file system to help both you and Linux find needed files.

There are two ways to manipulate the linux files: using the command line and the Midnight Commander.
We will be creating, deleting, copying, renaming, listing, linking, and protecting the files like a pro. Also we can wipe out the entire file system without really trying.

Q: How Do Linux File Directories Work?

Answer:
A Linux directory is a special file that acts as a container for other files and even other directories. You can create directories to hold groups of related files as an alternative to keeping all your files in one huge directory. A Linux file system is like a filing cabinet with a bunch of folders, each of which can contain subfolders and files.
Important file directories that work with Linux are explain below-
/bin: Contains the Linux system commands and programs (also called binaries
/dev: Contains special device files that correspond to hardware components.
/etc: Contains configuration files for Linux and other installed software
/home: Contains the home directories (personal storage) for each user on the system
/sbin: Contains more Linux binaries (special utilities not for general users).
/root: The home directory for the root user; not to be confused with /. Some Linux systems use /home/root instead of /root
/usr: Contains system programs and other files for general users such as games, online help, and documentation. By convention, a user should not put personal files in this directory.


Q: How can you move a cursor?

Answer:

A single function is provided for moving the cursor, with an additional command for controlling where curses leaves the cursor after screen updates. The move function simply moves the logical cursor position to the specified location. Calling move function won’t cause the physical cursor to move. It only changes the location on the logical screen.
             The leaveok function sets a flag that controls where curses leaves the physical cursor. By default, the flag is false, and the hardware cursor is left in the same position on the screen as the logical cursor. If the flag is set to true, the hardware cursor may be left randomly, anywhere on the screen.

Q: Write a short note on Text Editor.
Answer:
Text editors are similar to word processors, providing various features for writing documents.  Several text editors are available on Linux.
Vi:
Vi is often the default editor that pops up when we are ready to write an e-mail message or when we are posting a News message.  Vi is complicated and seems difficult to learn at first.  However, it is often the default for Unix and Linux systems
Pico:
Pico is a  simple text editor that provides straight-forward options and easy-to-use commands. However, Pico is not very good when manipulating certain types of files such as making changes to .cgi files etc.
Emacs:
Emacs is another editor available in UNIX. Like vi, emacs is a screen editor. Unlike vi, emacs is not an insertion mode editor, meaning that any character typed in emacs is automatically inserted into the file, unless it includes a command prefix.
Q: What is Emacs Editor?

Answer:
Emacs is another editor available in UNIX. Like vi, emacs is a screen editor. Unlike vi, emacs is not an insertion mode editor, meaning that any character typed in emacs is automatically inserted into the file, unless it includes a command prefix

Q: What is UNIX?

Answer:

UNIX is a powerful computer operating system. The UNIX operating system was developed at Bell Laboratories in 1969. UNIX operating systems are widely used in servers, workstations, and mobile devices. It is very popular among the scientific, engineering, and academic communities due to its multi-user and multi-tasking environment, flexibility and portability, electronic mail and networking capabilities, and the numerous programming, text processing and scientific utilities available. UNIX systems are characterized by various concepts:
Ø  The use of plain text for storing data;
Ø  A hierarchical file system;
Ø  The use of a large number of software tools;
Ø  Small programs that can be strung together through a command line interpreter using pipes.

Q: What are the advantages of UNIX operating system?

Answer:

The advantages of UNIX operating system are -

Ø  UNIX is flexible and can be installed on many different types of machines.
Ø  UNIX has greater built-in security.
Ø  UNIX is the leader in serving the Web.
Ø  UNIX is free or inexpensive open-source operating systems.
Ø  UNIX is a powerfully unified file system.

Q: Define Header files and Library files.

Answer:

Header files: A header file is a file containing C declarations and macro definitions to be shared between several source files. Some programming languages most famously C, C++, and Objective-C use header files.  Header files commonly contain forward declarations of classes, subroutines, variables, and other identifiers.
Library files: Libraries are collections of precompiled function that have been written to be reusable. They consist of sets of related functions to perform a common task. A library file name always starts with lib. Examples include libraries of screen-handling functions and database access routines.


Q: Define Static library and Shared library.

Answer:

Static Library: A static library or statically-linked library is a set of routines, external functions and variables which are resolved in a caller at compile-time. Static libraries are merged with other static libraries. Static libraries can be easily created in C or in C++.
Shared Library: Like an archive library, a shared library contains object code. It covers at least two different concepts. First, it is the sharing of code located on disk by unrelated programs. The second concept is the sharing of code in memory, when programs execute the same physical page of RAM, mapped into different address spaces

Q: What is Pipes?

Answer:

A very useful Linux feature is named pipes which enable different processes to communicate. A pipe is a technique for passing information from one program process to another. This allows tools quite narrow in their function to be combined in complex ways. A simple example of using a pipe is the command:
Is | grep x
 
Q: What is /proc file system?

Answer:

The /proc file system is a direct reflection of the system kept in memory and represented in a hierarchal manner. The effort of the /proc file system is to provide an easy way to view kernel and information about currently running processes. As a result, some commands read /proc directly to get information about the state of the system. The premise behind /proc is to provide such information in a readable manner instead of having to invoke difficult to understand system calls.

Q: What /proc file system can do for an Administrator?

Answer:

The /proc file system can be used for system related tasks such as:
  • Viewing Statistical Information.
  • Finding out Hardware Information.
  • Modifying Runtime Parameters.
  • Viewing and Modifying Network and Host Parameters.
  • Memory and Performance Information.

Q: What is Pathname Expansion or Filename Generation?

Answer:

Pathname expansion is also called filename generation is the process of interpreting ambiguous file references and substituting the appropriate list of filenames. The base syntax for the pathname expansion is the pattern matching syntax.

Q: What is the Bourne shell? Write the features of the Bourne shell.

Answer:

The Bourne shell is considered the primary shell in scripts. All UNIX systems have it, first of all. Second, the shell is small and fast. It doesn't have the interactive features of the C shell. Many consider the Bourne shell to be the best shell for writing portable UNIX scripts.
The Bourne shell, or sh, was the default Unix shell of Unix Version 7. Bourne shell scripts can typically be run with bash or dash on GNU/Linux or other Unix-like systems. The binary program of the Bourne shell or a compatible program is located at /bin/sh on most Unix systems, and is still the default shell.
Features of the Bourne shell include:
  • Scripts can be invoked as commands by using their filename.
  • May be used interactively or non-interactively.
  • Allow both synchronous and asynchronous execution of commands.
  • Supports input and output redirection and pipelines.
  • Provides a set of built-in commands.
  • Provides flow control constructs, quotation facilities, and functions.
  • Type less variables.
  • Provides local and global variable scope.
  • Scripts do not require compilation before execution.
  • Does not have a go to facility, so code restructuring may be necessary.

Q: What is Bash?

Answer:

Bash is the shell, or command language interpreter, for the GNU operating system. The name is an acronym for the ‘Bourne-Again Shell’.
Bash is largely compatible with sh. It is intended to be a conformant implementation of the ieee posix Shell and Tools portion of the ieee posix specification It offers functional improvements over sh for both interactive and programming use.
 Bash is the default shell. Bash is quite portable. It currently runs on nearly every version of UNIX.

Q: Explain shell basics? 

Answer:
The basic actions of the shell are simple. It reads a line. This is either from a file, a script, or from a user.
Ø  First, meta-characters are "handled."
Ø  Second, the name of the executable is found.
Ø  Third, the arguments are passed to the program.
Ø  Fourth, the file redirection is setup.
Ø  Lastly, the program is executed.

Q: Define Parameters and variables.

Answer:

A parameter is an entity that stores values. It can be a name, a number, or one of the special characters. A parameter is set if it has been assigned a value. The null string is a valid value.
A variable has a value and zero or more attributes. Attributes are assigned using the declare builtin command. Once a variable is set, it may be unset only by using the unset builtin command.
A variable may be assigned to by a statement of the form
     name=[value]

Q: Define Shell function.
Answer:

Shell functions are a way to group commands for later execution using a single name for the group. They are executed just like a "regular" command. When the name of a shell function is used as a simple command name, the list of commands associated with that function name is executed. Shell functions are executed in the current shell context; no new process is created to interpret them.
Functions are declared using this syntax:
     [function] name () compound-command [redirections]
 
 
Q: Explain controlling bash Features
and Options.

Answer:

Controlling bash features and options is explained using command line options and the set.

Command Line Options

Two kinds of command line options are available: short and long. Short options consist of a hyphen followed by a letter; long options have two hyphens followed by multiple characters. Long options must appear before short options on a command line that calls bash.


Bash features

 

Q: How can you process the Command Line?

 Answer:
Whether we are working interactively or running a shell script, bash needs to read a command line before it can start processing it—bash always reads at least one line before processing a command. When bash recognizes a command that covers more than one line, it reads the entire command before processing it. In interactive sessions bash prompts we with the secondary prompt as we type each line of a multiline command until it recognizes the end of the command:
After reading a command line, bash applies history expansion and alias substitution to the line.
History expansion is the process that bash uses to turn a history command into an executable command line.
Aliases substitute a string for the first word of a simple command. By default aliases are turned on for interactive shells and off for noninteractive shells.


Q: Define Threads and System Calls.

Answer:

Threads: Threads, like processes, are a mechanism to allow a program to do more than one thing at a time. As with processes, threads appear to run concurrently; the Linux kernel schedules them asynchronously, interrupting each thread from time to time to give others a chance to execute. Conceptually, a thread exists within a process.

System Calls: A system call is implemented in the Linux kernel. When a program makes a system call, the arguments are packaged up and handed to the kernel, which takes over execution of the program until the call completes. A system call isn’t an ordinary function call, and a special procedure is required to transfer control to the kernel.


Q: Explain about Debugging C programs.

Answer:

C programs are particularly challenging to debug because the C language does not limit what we can do. In particular, pointers are not only very powerful and flexible, they can also be dangerous. A large part of debugging C programs involves recognizing, understanding and correcting pointer bugs.

Types of Pointer Bugs

Pointer bugs arise from uninitialized pointers, dangling pointers and incorrect use of arguments to functions.
An uninitialized pointer is simply a pointer variable which is used before it has been given a value.
The second type of pointer bug is the dangling pointer. A dangling pointer refers to an area of memory which is no longer being used for its original purpose.
A third kind of pointer bug is the mistaken parameter bug. This kind of bug can be eliminated by using function prototyping.
Symptoms of Pointer Bugs

Ø  A library function suddenly crashes or produces erroneous results.
Cause: A pointer bug has corrupted the library function.

Ø  The symptoms of a bug change after we insert print statements.
Cause: The print statements changed the code corrupted by the pointer bug.


Ø  Control reaches a particular statement, but not the statement immediately following.
Cause: A pointer bug has corrupted one or both of the statements.

Ø  Our program calls a function, but control never reaches the function.
Cause: A pointer bug has corrupted the call stack or the function.

Ø  Control never returns from a function.
Cause: A pointer bug has corrupted the call stack or the function

 

Find and Fix Bugs


Fixing bugs is a two-step process. The following are the steps to find and fix bugs as follows:
·         Fill memory with a constant value before you run your program.
·         Eliminate the effects of most dangling pointers by disabling any routine which frees a dynamically allocated data structure.
·         Keep precise records about how you invoked your program.
·         Not to change our program during debugging if we can help it. The smallest changes in our program, or even a change in the order in which functions are linked together may cause the symptoms of pointer bugs to change or disappear.

Q: Why is the Shell So Important?

Answer:
The shell is our interface to executing programs, managing files and directories, etc. Though very few people are aware of it, they use the shell frequently in daily work, e.g., completing file names, using history substitution and aliases. The TCSH shell offers all of these features and a few more, which the average user seldom optimizes.
With a high knowledge of our shell's power, we can decrease the time we need to spend in the shell, and increase the time spent on original tasks.
Q: What do you mean by “File Descriptor”?
Answer:
File Descriptor: An integer that identifies an open file within a process. This number is obtained as a result of opening a file. Operations which read, write, or close a file would take the file descriptor as an input parameter. In many operating system implementations, file descriptors are small integers which index a table of open files. In Unix, file descriptors 0, 1 and 2 correspond to the standard input, standard output and standard error files respectively.

Q: Define TC shell.

Answer:

The TC Shell (tcsh) performs the same function as the Bourne Again Shell and other shells. It provides an interface between us and the Linux operating system. The TC Shell is an interactive command interpreter as well as a high-level programming language.

Q: What are the features common to Bourne Again and TC Shells?

Answer:
Common features are:
Ø  History
Ø  Aliases
Ø  Job control
Ø  Filename substitution
History: The use of history in tcsh is similar to its use in bash. The same event and word designators work in both shells. For example,!328 means to execute event number 328.
Aliases: Defining an alias is another way to minimize our work at the keyboard, and we can also eliminate the need to remember long, awkward commands by creating synonyms that are more meaningful to us.
Job control: Job control is the ability to move processes between the foreground and background. This is very useful when you need to do several things at once, but only have one terminal.
Filename substitution: The TC shell expands the characters *, ? and [] in a pathname just as bash does. The * matches any string of zero or more characters, ? matches any single character, and[] defines a character class, used to match single character appearing within a pair of brackets.

Q: How to working with a command line in a TC Shell? Explain it.

Answer:

Word Completion

The TC Shell completes filenames, commands, and variable  name on the command line when we prompt it to do so.
Filename Completion: The TC Shell can complete a file name after we specify a unique prefix.
TILDE Completion: The TC Shell parses a tilde (~) appearing the 1st character of a word and attempts to explain it to a user name when we enter a TAB.
Command and Variable Completion: We can use the same mechanism that we use to list and complete filenames with command and variable names.

Editing the Command Line

The tcsh command line editing feature is similar to that available under bash. We can use either emacs mode commands or vim mode commands. Change to vim mode commands by using bindkey –v and to emacs mode command by using bindkey -e.

Correcting Spelling

Spelling correction can take place only at two times: before and after press RETURN.
Before We Press RETURN: In here two functions are used namely spell-line and spell-word.
After We Press RETURN: The variable named correct controls what tcsh attempts to correct or complete after we press RETURN and before it passes the command line to the command being called. If we do not set correct, tcsh will not correct anything. 

Q: What are the advantages and disadvantages of threads?

Answer:
Advantages of threads:
Ø  Thread is very useful to make a program appear to do two things at once.
Ø  While the input or output thread is waiting for a connection, one of the other threads can continue with calculations.
Ø  Using multiple threads inside a process can enable a single process to better utilize the hardware resources available.
Ø  In general, switching between threads requires the operating system to do much less work than switching between processes.
Disadvantages of threads:
Ø  Writing multithreaded programs requires very careful design.
Ø  Debugging a multithreaded program is much, much harder than debugging a single-threaded one
Ø  A program that splits a large calculation into two parts as different threads will not necessarily run more quickly on a single processor machine.

Q: Define Filesystem.

Answer:

A Filesystem is a data structure that usually resides on part of a disk and that holds directories of files. Filesystems store user and system data that are the basis of user’s work on the system and the system’s existence.

Q: Define scanning directories. What are the scanning directory functions?

Answer:

Scanning Directories: Scanning directories are determining the file that resides a particular directory. A common problem on Linux systems is scanning directories.
The scanning directory functions are-
opendir: The opendir function opens a directory and establishes a directory stream.
readdir: The readdir function returns a pointer to a structure detailing the next directory entry in the directory stream dirp.
telldir: The telldir function returns a value that records the current position in a directory stream.
seekdir: The seekdir function sets the directory entry pointer in the directory stream given by dirp.
closedir: The closedir function closes a directory stream and frees up the resources associated with it. It returns 0 on success and -1 if there is an error.

Q: Why should I use an editor?

Answer:

It is very important to be able to use at least one text mode editor. Knowing how to use an editor on our system is the first step to independence. We need it to edit files that influence our environment. As an advanced user, we may want to start writing scripts, or books, develop websites or new programs. Mastering an editor will immensely improve our productivity as well as our capabilities.


Q: What are the disadvantages of LINUX?

Answer:

Disadvantages -
1.Not easy to use (even with the easy-to-use distros)
2.Sometimes lacking hardware support (ie, newer laptop network cards, etc)
3.Lack of newer games
4.Lack of powerful specific software (like CAD, etc)

 
Q: What are the types of Shell?

Answer:

Different shell types:

sh or Bourne Shell: The Bourne shell is considered the primary shell in scripts. All UNIX systems have it, first of all. Second, the shell is small and fast. It doesn't have the interactive features of the C shell. Many consider the Bourne shell to be the best shell for writing portable UNIX scripts.
bash or Bourne Again shell: Bash is the shell, or command language interpreter, for the GNU operating system. The name is an acronym for the ‘Bourne-Again Shell’.
Bash is largely compatible with sh. It is intended to be a conformant implementation of the ieee posix Shell and Tools portion of the ieee posix specification It offers functional improvements over sh for both interactive and programming use.
Bash is the default shell. Bash is quite portable. It currently runs on nearly every version of UNIX.
csh or The C shell is a command processor that's typically run in a text window, allowing the user to type commands which cause actions. The C shell can also read commands from a file, called a script.

tcsh: TC Shell (tcsh) performs the same function as the Bourne Again Shell and other shells. It provides an interface between us and the Linux operating system. The TC Shell is an interactive command interpreter as well as a high-level programming language.


ksh or the Korn shell: It is backwards-compatible with the Bourne shell and includes many features of the C shell as well, such as a command history, which was inspired by the requests of Bell Labs users. The main advantage of ksh over the traditional Unix shell is in its use as a programming language.



Edited By Dushmanta Nath