Thursday 25 August 2011

What is Processes

Process is kind of program or task carried out by your PC. For e.g.
$ ls -lR

Process defined as:
"A process is program (command given by user) to perform specific Job. In Linux when we start process, it gives a number to process (called PID or process-id), PID starts from 0 to 65535."

As We know Linux is multi-user, multitasking Os. It means we can run more than two process simultaneously if we wish. For e.g. To find how many files do we have on your system we may give command like:

$ ls / -R | wc -l

This command will take lot of time to search all files on your system. So we can run such command in Background or simultaneously by giving command like

$ ls / -R | wc -l &

The ampersand (&) at the end of command tells shells start process (ls / -R | wc -l) and run it in background takes next command immediately.
Process & PID defined as:
"An instance of running command is called process and the number printed by shell is called process-id (PID), this PID can be use to refer specific running process."

Following tables most commonly used command(s) with process:
For this purposeUse this CommandExamples*
To see currently running process ps$ ps
To stop any process by PID i.e. to kill processkill    {PID}$ kill  1012
To stop processes by name i.e. to kill processkillall   {Process-name}$ killall httpd
To get information about all running processps -ef$ ps -ef
To stop all process except your shellkill 0$ kill 0
For background processing (With &, use to put particular command and program in background)linux-command  &$ ls / -R | wc -l &
To see if a particular process is running or not. For this purpose you have to use ps command in combination with the grep command  ps -ef | grep  process-U-want-to seeFor e.g. you want to see whether Apache web server process is running or not then give command$ ps -ef | grep httpd
To see currently running processes and other information like memory and CPU usage with real time updates.top
See the output of top command.

$ top


Note
that to exit from top command press q.

Pipes

A pipe is a way to connect the output of one program to the input of another program without any temporary file.
Pipe - Redirecting output of 1st command to 2nd without creating temporary file
Pipe Defined as:
"A pipe is nothing but a temporary storage place where the output of one command is stored and then passed as the input for second command. Pipes are used to run more than two commands ( Multiple commands) from same command line."
Syntax:
command1 | command2

Filter

If a Linux command accepts its input from the standard input and produces its output on standard output is know as a filter. A filter performs some kind of process on the input and gives output. For e.g.. Suppose you have file called 'hotel.txt' with 100 lines data, And from 'hotel.txt' you would like to print contains from line number 20 to line number 30 and store this result to file called 'hlist' then give command:
$ tail +20 < hotel.txt | head -n30 >hlist
Here head command is filter which takes its input from tail command (tail command start selecting from line number 20 of given file i.e. hotel.txt) and passes this lines as input to head, whose output is redirected to 'hlist' file.
Consider one more following example
$ sort < sname | uniq > u_sname
Here uniq is filter which takes its input from sort command and passes this lines as input to uniq; Then uniqs output is redirected to "u_sname" file.

 Example :-
-bash-3.00$ ls -lrt
total 5828
-rwxrwxrwx   1 qa1      qa       1350256 Jun 11  2010 opx_PAR_ERI_720
-rwxrwxrwx   1 qa1      qa       1597852 Jun 22 03:20 opx_PAR_ERI_6as
-rwxrwxrwx   1 qa1      qa            91 Aug  8 07:16 Din
-rwxrwxrwx   1 qa1      qa            26 Aug  8 07:19 sname
-bash-3.00$ for i in $(ls -lrt)
> do
> echo $i
> done
total
5828
-rwxrwxrwx
1
qa1
qa
1350256
Jun
11
2010
opx_PAR_ERI_720
-rwxrwxrwx
1
qa1
qa
1597852
Jun
22
03:20

-bash-3.00$ IFS="
> "
-bash-3.00$ for i in $(ls -lrt); do echo $i; done
total 5828
-rwxrwxrwx   1 qa1      qa       1350256 Jun 11  2010 opx_PAR_ERI_720
-rwxrwxrwx   1 qa1      qa       1597852 Jun 22 03:20 opx_PAR_ERI_6as
-rwxrwxrwx   1 qa1      qa            91 Aug  8 07:16 Din
-rwxrwxrwx   1 qa1      qa            26 Aug  8 07:19 sname
-rwxrwxrwx   1 qa1      qa            26 Aug  8 07:21 sorted_name
-rwxrwxrwx   1 qa1      qa            26 Aug  8 07:23 cap_names
-rwxrwxrwx   1 qa1      qa            26 Aug  8 07:26 new_sorted_names
-rwxrwxrwx   1 qa1      qa            44 Aug  8 07:50 er



Monday 8 August 2011

Unix : I/O Redirection

There are three main redirection symbols >,>>,<
1) Linux-command > filename
eg:-

$ ls > myfiles
Now if 'myfiles' file exist in your current directory it will be overwritten without any type of warning.

2) Linux-command >> filename 
 eg:-
$ date >> myfiles 
To output Linux-commands result (output of command or shell script) to END of file. Note that if file exist , it will be opened and new information/data will be written to END of file, without losing previous information/data, And if file is not exist, then new file is created.

3) Linux-command < filename
eg:-
$ cat < myfiles 
To take input to Linux-command from file instead of key-board. For e.g. To take input for cat command give 


$cat > sname
vivek
ashish
zebra
babu
Press CTRL + D to save.

$ sort < sname > sorted_names
$ cat sorted_names
ashish
babu
vivek
zebra

$ tr "[a-z]" "[A-Z]" < sname > cap_names
$ cat cap_names
VIVEK
ASHISH
ZEBRA
BABU

tr command is used to translate all lower case characters to upper-case letters. It take input from sname file, and tr's output is redirected to cap_names file 

For sorting in descending order:-
$ sort -r 


 
 

Friday 5 August 2011

Why Command Line arguments required


  1. Telling the command/utility which option to use.
  2. Informing the utility/command which file or group of files to process (reading/writing of files). 
To run two command with one command line.
Syntax:
command1;command2

$ date;who

Get input from keyboard and store to a variable.

-bash-3.00$  vi Din
echo "Enter The Number : "
read num
echo "Square of your number is `expr $num \* $num` "

bash-3.00$ chmod +x *
-bash-3.00$ ./Din
Enter The Number :
4
Square of your number is 16

Use of  bc command:-
-bash-3.00$ bc
scale=2
10 / 3
3.33
scale=5
10 / 3
3.33333


OR

-bash-3.00$ echo "scale=2" > myfile
-bash-3.00$ echo "5 / 2" >> myfile
-bash-3.00$ bc < myfile
2.50












UNIX : Quotes


There are three types of quotes
Quotes
Name
Meaning
" Double Quotes "Double Quotes" - Anything enclose in double quotes removed meaning of that characters (except \ and $).
' Single quotes 'Single quotes' - Enclosed in single quotes remains unchanged.
` Back quote
`Back quote` - To execute command

Example:
-bash-3.00$  echo "Today is date"
Today is date
-bash-3.00$ echo "Today is `date`".
Today is Friday,  5 August 2011 05:49:13 IST.
-bash-3.00$ echo "sum is `expr 2 + 3` "
sum is 5


By default in Linux if particular command/shell script is executed, it return two type of values which is used to see whether command or shell script executed is successful or not.
(1) If return value is zero (0), command is successful.
(2) If return value is nonzero, command is not successful or some sort of error executing command/shell script.
This value is know as Exit Status

To determine this exit Status you can use $? special variable of shell.

-bash-3.00$ rm unknowfile
unknow1file: No such file or directory
-bash-3.00$ echo $?
2
-bash-3.00$ ls
d                Din.sh           opx_PAR_ERI_6as
dev              first            opx_PAR_ERI_720
-bash-3.00$ echo $?
0
-bash-3.00$ expr 1 + 3
4
-bash-3.00$ echo $?
0



Unix : Display colorful text on screen


Parameter Meaning Example
0 Sets default color scheme (White foreground and Black background), normal intensity, no blinking etc.  
1 Set BOLD intensity $ echo -e "I am \033[1m BOLD \033[0m Person"I am BOLD Person
Prints BOLD word in bold intensity and next ANSI Sequence remove bold effect (\033[0m)
2 Set dim intensity $ echo -e "\033[1m  BOLD \033[2m DIM  \033[0m"
5 Blink Effect $ echo -e "\033[5m Flash!  \033[0m"
7 Reverse video effect i.e. Black foreground and white background in default color scheme $ echo -e "\033[7m Linux OS! Best OS!! \033[0m"
11 Shows special control character as graphics character. For e.g. Before issuing this command press alt key (hold down it) from numeric key pad press 178 and leave both key; nothing will be printed. Now give --> command shown in example and try the above, it works. (Hey you must know extended ASCII Character for this!!!) $ press alt + 178
$ echo -e "\033[11m"
$ press alt + 178
$ echo -e "\033[0m"
$ press alt + 178
25 Removes/disables blink effect  
27 Removes/disables reverse effect  
30 - 37 Set foreground color
31 - RED
32 - Green
xx - Try to find yourself this left as exercise for you :-)
$ echo -e "\033[31m I am in Red"
40 - 47 Set background color
xx - Try to find yourself this left as exercise for you :-)
$ echo -e "\033[44m Wow!!!"

UNIX : echo Command


Use echo command to display text or value of variable.
echo [options] [string, variables...]
Displays text or variables value on screen.
Options
-e Enable interpretation of the following backslash escaped characters in the strings:
\b backspace
\c suppress trailing new line
\n new line
\r carriage return
\t horizontal tab
\\ backslash
For e.g. $ echo -e "Everyday is not \a\t\tSunday\n"

expr 20 %3 - Remainder read as 20 mod 3 and remainder is 2.
expr 10 \* 3 - Multiplication use \* and not * since its wild card.

ls Command:-

-bash-3.00$ ls *
d                dev              Din              first            myfile           opx_PAR_ERI_6as  opx_PAR_ERI_720


-bash-3.00$ ls [def]*
d      dev    first


-bash-3.00$ ls [d-f]*
d      dev    Din    first



$ ls ?   will show all files whose names are 1 character long 
$ ls fo? will show all files whose names are 3 character long and file name begin with fo.
$ ls /bin/[!a-o]
$ ls /bin/[^a-o]

If the first character following the [ is a ! or a ^ ,then any character not enclosed is matched i.e. do not show us file name that beginning with a,b,c,e...o.


Friday 29 July 2011

Developer's Choice: Shell Script :

Developer's Choice: Shell Script :: "' Shell Script is series of command written in plain text file . Shell script is just like batch file is MS-DOS but have more power than..."

Thursday 28 July 2011

Shell Script :


"Shell Script is series of command written in plain text file. Shell script is just like batch file is MS-DOS but have more power than the MS-DOS batch file."

Use of Shell Script

  • Shell script can take input from user, file and output them on screen.
  • Useful to create our own commands.
  • Save lots of time.
  • To automate some task of day today life.
We may find all running process by using:-
        $ ps ef
                                         
Find process with the specific_name(For eg- process-name)
       $ ps ef | grep process-name

    Wednesday 27 July 2011

    UNIX : KERNEL

    What Kernel Is?
    Kernel is heart of Linux Os.
    It manages resource of Linux Os. Resources means facilities available in Linux. For e.g. Facility to store data, print data on printer, memory, file management etc .

    Kernel decides who will use this resource, for how long and when. It runs your programs (or set up to execute binary files).

    The kernel acts as an intermediary between the computer hardware and various programs/application/shell.
                     

    It's Memory resident portion of Linux. It performance following task :-

    I/O management
    Process management
    Device management
    File management
    Memory management

    Linux Shell  
    Computer understand the language of 0's and 1's called binary language.
    In early days of computing, instruction are provided using binary language, which is difficult for all of us, to read and write. So in Os there is special program called Shell. Shell accepts your instruction or commands in English (mostly) and if its a valid command, it is pass to kernel.
    Shell is a user program or it's environment provided for user interaction. Shell is an command language interpreter that executes commands read from the standard input device (keyboard) or from a file.
    Shell is not part of system kernel, but uses the system kernel to execute programs, create files etc.

    Types Of Shell
    BASH ( Bourne-Again SHell )
    CSH (C SHell)
    KSH (Korn SHell)
    TCSH

    Note that each shell does the same job, but each understand a different command syntax and provides different built-in functions.
    Any of the above shell reads command from user (via Keyboard or Mouse) and tells Linux Os what users want. If we are giving commands from keyboard it is called command line interface ( Usually in-front of $ prompt, This prompt is depend upon your shell and Environment that you set or by your System Administrator, therefore you may get different prompt ).
    To find your current shell type following command
    $ echo $SHELL




    Monday 25 July 2011

    SQL SERVER

    FIND NAME OF DATABASE IN SQL SERVER

    select * from sys.databases

    FIND NAME OF TABLES IN DATABASE

    use DATABASE_NAME
    go
    select * from sys.tables
    go

    FETCH DATA FROM A TABLE

    SELECT * FROM TABLE_NAME

    Thursday 21 July 2011

    FTP : File Transfer from Local System to Server

    Step 1 : Open Command Prompt
    Step 2 : Go to Source Directory
    Step 3 : ftp Ip_Adddress(For eg: ftp 192.168.99.53)
    Step 4 : login Credentials
    Step 5 : Go to Destination Directory
    Step 6 : bin
    Step 7 : mput (OR mget)
    Step 8 : bye

    REMARK : "mput" and "mget" is used to transfer multiple file from source to destination and destination to source directory respectively.
    ("put" and "get" command can be used for single file transfer )

    Wednesday 20 July 2011

    XML encoding list


    XML encoding list
    [96264 urls; 154 unique values]


    PopularityValueFrequency
    1iso-8859-154572
    2utf-827052
    3iso-8859-23919
    4shift_jis2464
    5utf-161688
    6windows-12511291
    7windows-12501127
    8iso-8859-9832
    9windows-1252731
    10euc-jp668
    11iso-8859-15615
    12us-ascii181
    13big5155
    14gb2312148
    15windows-125784
    16windows-125578
    17iso-2022-jp54
    18iso-8859-749
    19windows-125644
    20iso-8859-1338
    21utf832
    22\"utf-8\"28
    23tis-62026
    24shift-jis19
    25koi8-r19
    26euc-kr16
    27windows-125414
    28charset=iso-8859-113
    29iso8859-113
    30\"iso-8859-1\"12
    31latin112
    32cp125111
    33iso 8859-1510
    34x-sjis9
    35"windows-1252"9
    36iso 8859-19
    37windows-8747
    38iso8859-26
    39charset6
    40iso-8859-8-i6
    41gbk6
    42iso-8859-46
    43windows-12535
    44\"iso-8859-2\"4
    45windows-31j4
    46win-12504

    Monday 18 July 2011

    Windows NT startup process

    The Windows NT startup process is the process by which Microsoft's Windows NT, Windows 2000, Windows XP and Windows Server 2003 operating systems initialize.

    Boot Sequence

    • Upon POWER ON, the CPU runs the instruction located at the memory location 0xFFFF0 of the BIOS.
    • 0xFFFF0 contains a JUMP Instruction pointing to the BIOS start-up program, which then runs the POST to check & initialize required devices.
    • The BIOS checks a pre-configured list of Non-Volatile Storage Devices (Boot Device Sequence)
    • A bootable device has the last 2 bytes of the first sector containing 0xAA55 (Boot Signature)
    • Once identified, BIOS loads the Boot Sector contents (from MBR in case of a HDD) to memory & transfers execution control to the boot code.
    • MBR Code looks for a bootable partition from its Partition Table.
    • The MBR code loads the boot sector code from that partition and executes it.
    • The Boot Sector Code is mostly OS Specific which loads and executes the OS Kernel.
    • If no Active Partition or invalid Active Partition Boot Sector, the MBR loads a secondary Loader to select the partition via user input.
    From that point, the boot process continues as follows:

    An NTLDR file, located in the root folder of the boot disk, is composed of two parts. The first is the StartUp module and immediately followed by the OS loader (osloader.exe), both stored within that file. When NTLDR is loaded into memory and control is first passed to StartUp module, the CPU is operating in real mode. StartUp module's main task is to switch the processor into protected mode, which facilitates 32-bit memory access, thus allowing it to create the initial Interrupt descriptor table, Global Descriptor Table, page tables and enable paging. This provides the basic operating environment on which the operating system will build. StartUp module then loads and launches OS loader.



    Disable/Enable Windows default debugger Dr. Watson

    If you feel it's useless for you anyway, just follow these steps to turn off.

    1.Go to Start Menu -->> Run and type regedit.exe then press Enter.

    2.Browse to the following registry. HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\AeDebug

    3.Click the AeDebug key, and then click Export Registry File on the Registry menu. Save the file and remember it.

    4.Then you can delete the AeDebug key.
     
    That's it! Whenever any programs crash again, Windows won't ask you whether you want to send data to Microsoft or not.

    If you change your mind and want to enable Dr. Watson back. It's easy.
    * Double-click the file you save in step 3.
    * And then go to Start -->> Run -->> cmd.exe
    * At the command prompt, type drwtsn32 -i