Sunday, September 23, 2012

Display current time in the prompt

UNIX Display current time in the prompt:
----------------------------------------------
In the PS1 environment variable, you can directly execute any Linux command, by specifying in the format $(linux_command). In the following example, the command "date" is executed to display the current time inside the prompt.

devaraj#export PS1="\u@\h [\$(date +%H:%M:%S)]# "
devaraj@my-serv [14:12:35]#
devaraj@my-serv [14:12:35]# date
Sun Sep 23 14:12:37 IST 2012

What Is a Kernel

What Is a Kernel?
--------------------

Let's start by providing a definition for the term kernel. The UNIX kernel is the software that manages the user program's access to the systems hardware and software resources. These resources range from being granted CPU time, accessing memory, reading and writing to the disk drives, connecting to the network, and interacting with the terminal or GUI interface. The kernel makes this all possible by controlling and providing access to memory, processor, input/output devices, disk files, and special services to user programs.

Kernel Services:
------------------

The basic UNIX kernel can be broken into four main subsystems:

Process Management
Memory Management
I/O Management
File Management

These subsystems should be viewed as separate entities that work in concert to provide services to a program that enable it to do meaningful work. These management subsystems make it possible for a user to access a database via a Web interface, print a report, or do something as complex as managing a 911 emergency system. At any moment in the system, numerous programs may request services from these subsystems. It is the kernel's responsibility to schedule work and, if the process is authorized, grant access to utilize these subsystems. In short, programs interact with the subsystems via software libraries and the systems call interface. Refer to your UNIX reference manuals for descriptions of the systems calls and libraries supported by your system. Because each of the subsystems is key to enabling a process to perform a useful function, we will cover the basics of each subsystem. We'll start by looking at how the UNIX kernel comes to life by way of the system initialization process.

Saturday, September 22, 2012

commands

du -adk . | sort -nr 

find command

Separate filenames using the null character:
--------------------------------------------------

find . -name "*.foo" | xargs grep bar

in practice does the same as

grep bar `find . -name "*.foo"`

but will work even if there are so many files to search that they will not all fit on a single command line. It searches in all files in the current directory and its subdirectories which end in .foo f
or occurrences of the string bar.

find . -name "*.foo" -print0 | xargs -0 grep bar

does the same thing, but uses GNU specific extensions to find and xargs to separate filenames using the null character; this will work even if there are whitespace characters, including newlines, 

Zombie process

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

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

Zombie : The process is dead but have not been removed from the process table.

UNIX Single-User Mode:

UNIX Single-User Mode:
--------------------------
This mode can be reached through the automatic reboot sequence, or by the user booting with the -s option or setting the boot_single variable in loader.

It can also be reached by calling shutdown(8) without the reboot (-r) or halt (-h) options, from multi-user mode.

If the system console is set to insecure in /etc/ttys, then the system prompts for the root password before initiating single-user mode.

Example 13-3. An Insecure Console in /etc/ttys

# name getty type status comments
#
# If console is marked "insecure", then init will ask for the root password
# when going to single-user mode.
console none unknown off insecure

Note: An insecure console means that you consider your physical security to the console to be insecure, and want to make sure only someone who knows the root password may use single-user mode, and it does not mean that you want to run your console insecurely. Thus, if you want security, choose insecure, not secure.

Linux boot sequence

Booting the Linux operating system:
----------------------------------------

The first thing a computer does on start-up is a primer test (POST - Power On Self Test). This way several devices are tested, including the processor, memory, graphics card and the keyboard. Here is tested the boot medium (hard disk, floppy unit, CD-ROMs). After POST, the loader from a ROM loads the boot sector, which in turn loads the operating system from the active partition.
The boot blocks is always at the same place: track 0, cylinder 0, head 0 of the device from which we're booting. This block contains a program called loader, which in Linux's case is LiLo (Linux Loader), or Grub (GNU Grub Unified Boot Loader), which actually boots the operating system. These loaders in Linux , in case of a multi-boot configuration (more operating systems on a computer), permit the selection of the operating system to be booted. Lilo and Grub are installed or at the MBR (Master Boot Record), or at the first sector of the active partition.
In the following we will refer to LiLO as boot loader. This is usually installed in the boot sector, also known as MBR. If the user decides to boot Linux, LiLo will try to load the kernel. Now I will present step-by-step LiLo's attempt to load the operating system.

1. In case of a multi-boot config, LiLo permits the user two choose an operating system from the menu. The LiLo settings are stored at /etc/lilo.conf. System administrators use this file for a very detailed finement of the loader. Here can be manually set what operating systems are installed, as well as the method for loading any of them. If on the computer there is only Linux, LiLo can be set to load directly the kernel, and skip the selection menu.

2. The Linux kernel is compressed, and contains a small bit, which will decompress it. Immediately after the first step begins the decompression and the loading of the kernel.

3. If the kernel detects that your graphics card supports more complex text modes, Linux allows the usage of them - this can be specified or during the recompilation of the kernel, or right inside Lilo, or other program, like rdev.

4. The kernel verifies hardware configuration (floppy drive, hard disk, network adapters, etc) and configures the drivers for the system. During this operation, several informative messages are shown to the user.

5. The kernel tries to mount the file system and the system files. The location of system files is configurable during recompilation, or with other programs - LiLo and rdev. The file system type is automatically detected. The most used file systems on Linux are ext2 and ext3. If the mount fails, a so-called kernel panic will occur, and the system will "freeze".
System files are usually mounted in read-only mode, to permit a verification of them during the mount. This verification isn't indicated if the files were mounted in read-write mode.

6. After these steps, the kernel will start init, which will become process number 1, and will start the rest of the system.