Saturday, January 19, 2013

UNIX Architecture

There are two major agencies on which UNIX depends are :Kernel and Shell. The Kernel interacts with the machines hardware, and the Shell is interacts with the user of the machine. The diagram below shows the architecture of UNIX



Kernel


    • It is the core of the operating system, a collection of routines mostly written in C.
    • It is loaded into memory when the system is booted and communicates directly with the hardware.
    • User programs/applications that need to access the hardware like hard disk or terminal that use the services of the kernel, which performs the job on the users behalf. These programs access the kernel through a set of functions called system calls.
    • It manages the systems memory, schedules processes, decides their priorities, and performs other tasks.

    Shell

    • Computers don't have any inherent capability of translating commands into action. That requires a command interpreter, a job that is handled by the "Outer Part" of the operating system.
    • Shell is interface between the user and kernel. Even though there's only one kernel running on the system, there could be several shells in action-one for each user who is logged in.

    Why UNIX?

    Control

    • Commands often provide complete access to the system and its devices.
    • Most devices can be manipulated just like files

    Flexibility

    • Commands are just programs.
    • Commands have common interface to allow inter-operation with other commands.
    • Unix offers thousands of tools that can be combined and recombined.

    Reliability

    • Commands are typically lightweight since they typically do little more than invoke operating system calls.
    • Unix is hard to crash.
    • Provide multitasking, each user can perform multiple task easily.

    Powerful

    • Unix as an operating system can support almost any kind of software.
    Note :
             UNIX was developed at AT&T Bell Laboratories by Ken Thompson and Dennis Ritchie. It was finally written in C.
             All UNIX flavors today offer a graphical user interface (GUI) in the X Window system. But the strength of UNIX lies in its commands and options.

    Wednesday, January 2, 2013

    Unix File System

    File

    • File is a container for storing information.
    • It stored sequence of characters,it doesn't contain the eof(end-of-file) mark like DOS files.
    • A file's size is not stored in the file, nor even its name.
    • All file attributes are kept in a separate area of the hard disk, not directly accessible to humans, but only to the kernel.
    Unix treats directories and devices as files as well. A directory is simply a folder where you store filenames and other directories. All physical devices like the hard disk, memory, CD-ROM, printer and modem are treated as files. The below picture depicts the file structure.



    The implicit features of every UNIX file system is that there is a top, which serves as the reference point for all files. This top is called root and is represented by a / (front-slash). root is a directory. It is conceptually different from the user-id root used by the system administrator to log in.

    The root directory (/) has a number of subdirectories under it. These subdirectories in turn have more subdirectories and other files under them.  For instance, usr and home are two directories directly under /, while a second tim,jane,tom and julia are subdirectories are home.

    Every file , apart from root, must have a parent and it should be possible to trace the ultimate parentage of a file to root. Thus, the home directory is the parent of jane, while / is the parent of home, and the grandparent of jane. If you create a file prog under jane directory, then jane will be parent of this file.

    It's also obvious that, in these parent-child relationships, the parent is always a directory. home and jane are both directories as they are both parents of at least one file or directory. prog is simply an ordinary file. it cant have any directory under it.

    Tuesday, January 1, 2013

    WHILE LOOP in Shell Script Example

    Each while loop consists of a set of commands and a condition

    general syntax as follows for bash while loop:

    while [ condition ]do
     command1
     command2
     commandN
    done
    1. The condition is evaluated, and if the condition is true, the command1,2…N is executed.
    2. This repeats until the condition becomes false.
    3. The condition can be integer ($i < 5), file test ( -e /tmp/lock ) or string ( $ans != "" )
    Example :

    x=1;
    while [ $x -lt 10 ] ; do
    (( x++ ))
    echo "x = $x"
    done


    OUTPUT :

    -bash-3.2$ sh while_sh
    x = 2
    x = 3
    x = 4
    x = 5
    x = 6
    x = 7
    x = 8
    x = 9
    x = 10
    -bash-3.2$
    The while loop should be executed upto the condition failed (1<10)

    UNTIL loop example in Shell Script

    LIMIT=10
    var=0
    until (( var > LIMIT ))
    do  # ^^ ^     ^     ^^   No brackets, no $ prefixing variables.
      echo -n "$var "
      (( var++ )) ## increment operator in shell script
    done    # 0 1 2 3 4 5 6 7 8 9 10
    echo
    exit 0

    OUTPUT :

    -bash-3.2$ sh until_sh
    0 1 2 3 4 5 6 7 8 9 10
    -bash-3.2$

    Shell Script Function can return the value upto 255 example

    #!/bin/bash
    # The largest positive value a function can return is 255.
    return_test ()         # Returns whatever passed to it.
    {
      return $1
    }
    return_test 27         # o.k.
    echo $?                # Returns 27.
     
    return_test 255        # Still o.k.
    echo $?                # Returns 255.
    return_test 257        # Error!
    echo $?                # Returns 1 (return code for miscellaneous error).
    exit 0

    OUTPUT :

    -bash-3.2$ sh func_return_limit
    27
    255
    1
    -bash-3.2$

    IF ELSE & IF ELIF IF in Shell Script

    #!/bin/bash
    x=10
    y=20
    echo "Value x=$x y=$y"
    if [ $x -eq $y ] ; then
            echo -e " x and y are same value "
    elif [ $x -gt $y ] ; then
            echo -e " x is greater than y "
    else
            echo -e " x is less than y"
    fi

    str1="Chidam"
    str2="Chidam"
    echo "Value str1=$str1 str=$str2"
    if [ "$str1" = "$str2" ] ; then
            echo -e " str1 and str2 are same value "
    else
            echo -e " str1 and str2 are not same value "
    fi


    OUTPUT :

    -bash-3.2$ sh if_elif_ex
    Value x=10 y=20
     x is less than y
    Value str1=Chidam str=Chidam
     str1 and str2 are same value

    Table Lock - Query in Oracle APPS

     SELECT client_identifier,        module,        action,        s.*   FROM v$session s  WHERE sid IN (SELECT session_id                  FRO...