Thursday 23 January 2014

HTTP Post VS Get


When HTTP was designed, the HTTP client should use different ways to communicate with web server. For example:

  • GET for retrieving the information
  • POST for updating the information
  • PUT for adding the information
  • DELETE for deleting the information

But the programmer may do tricky things to use GET to cover the other methods. They could use GET to do data update at the backend. We need to understand what is the difference between GET and POST when updating the data.
  • Using GET, the data will be added in the URL as here: login.action?name=hyddd&password=idontknow .While using POST, the data is part of the HTTP content
  • Limitation of the data-length. While HTTP itself does not set limitation for URL and web content. Most of the browser will have their limitation.
  • Security: the content of GET will be showing in the url which is easier to be seen. Although the transsion traffic can be encrypted by HTTPS. The page could be cached/viewed and can cause security problem.
  • Also by theory, GET should be idempotent which means multiple operations should always return the same result.

Tuesday 21 January 2014

Linux interview preparation - kernel internal

here are some questions I prepared for a technical internal. these are about the Linux internals. hope it will help all others needs them in future.

What is inode?
What is the super block of the file system?
What is the difference between softlink and hardlink?
What is the virtual memory and it’s advantage?
What is Linux user mode or kernel mode?
How many inter process communication ways?
In a 32 bit linux, how user space and kernel space are allocated. 64 bit?
How many file types:
How a process and thread is created in linux:
how syscall works:
What is copy-on-write:
How many locks in linux kernel.
What is preempt?
Explain the CFS:
Explain the linux kernel scheduler:
How does an interrupt work?
What is the top half and bottom half. List the ways of bottom half.
What is the memory zone in linux. How many zones
Explain the slab.
What is VFS and it’s function.
List the objects in VFS. List some of normal operations.
What is the Logical and Physical Address for a process.
Difference between thread and processes
Why can’t make hark links for directories
What is the page table in linux kernel and how it is implemented?

What’s the syscall for create a process

linux interview preparation - linux operation

Explain different runlevels:
How many ways of restarting linux:
How many file types:
List the pseudo files in /dev/
How to change the hostname of the linux server
Where is the DNS server configured.
How to review the routing table of the linux box:
How to add a route entry in the linux box
What does dynamic link, how to view the dynamic library.
How to install software by source file: what does these steps mean?
What is initrd file in /boot/ does?
How to check if the TCP port is open ? how to find which process is opening it.
When create a directory, how many harklink you will get?
Why can’t make hark links for directories
Where is the network interface eth0 configuration file and where is the DNS configuration file.
How to find the files containing ‘abc’ and replace with ‘edf’


techical interview malicious questions

ftp passive/active:
ftp binary/ascii:
how DNS works
DNS which port, TCP vs UDP:
Primary DNS, secondary DNS, cached DNS:
Explain what is ARP
Reserverd IP:
What is DMZ:
TCP handshake/ bye process:
How to work on an incident like the websites are reporting slowness:
What’s happens when you type http://www.google.com in your browser

linux performance monitoring



Linux Performance monitoring
Performance monitoring is a hard job for system admin. It depends on the application running on the box and also the experience of the sys admin. Here are some basic guide for performance measuring.

Good
warning
Bad
CPU
user+sys < 70%
70%<user+sys<90%
user+sys > 70%
Memory
no swap
per CPU < 10 pages/s
lots of SI/SO
DISK
iowait < 20%
20% < iowait < 50%
iowait > 50%

Here we will show about the performance measuring tools and the output.
1.       vmstat: commands: vmstat [interval] [counters]
vmstat is a useful tool to analyse the performance.


Procs: process number:
                r: runnable process but waiting for CPU resource. If there are lots of r, it usually means the cpu resource is not enough (experience value < 2/cpu)
                b: blocked processes waiting for other resource (usually memory or IO)

Memory: memory information:
                swpd:  swaped memory measured by kb
                free:   usable memory
                buff:  buffered memory
                cache: cached memory
swap: swap information
                si: swap in. from disk to memory
                so: swap out. From memory to disk
IO: block IO information:
                Bi: block in. read from disk to memory
                Bo: block out. Write the memory information to disk.
System: 
                In: interruption numbers
                cs: content switch numbers
                there shouldn’t be many Interruptions and content switching for a stable system.
CPU: cpu usage by percentage
                Us: user level, sy: system level, id: idle. Wa: wait for IO.

free command:


Free command is very simple. Just need to understand the
Buffers: blocked IO related memory
Cached: file content cached.

Uptime: 

Showing the current time,  system running time since the last reboot and the current users. It will show the system load for the last min, 5 mins and 15 mins. It should consider the cpu cores when measuring the load.

iostat: check the disk IO status
The most important value is the %iowait: it is usually beblow 20%
%util. the lower the better.

Thursday 9 January 2014

SHELL Flow control structure




There are a few common instruction flow control structure in BASH including if, case, while, for, until. This blog will give a brief introduction. 

IF: to execute the commands according to the expression value.

The basic structure is
If [expression] ; then

[commands]

else

[commands]

fi

example:



CASE: multiple value evaluation structure.

case [expression] in

       mode1 [| mode2] ) commands;;

       mode3 [| mode4] ) commands;;

       mode5 [| mode6] ) commands;;

       *) commands;;

esac

for example:



Select: generate a menu for use to select from. Usually combined with CASE

Example:



While : loop the commands while the expression value is true

While [expression] ; do

[commands]
Done





For loop: iterate the variable in the parameter list


format:
for variable in list
do

commands

done
example:












break and continue are used to change the normal loop/while flow:


  • break: exit the loop/while structure
  • continue: ignore the left commands but start the next round of loop/while again.




Wednesday 8 January 2014

LINUX Device



In Linux, devices can usually classified as the below three typies:

  • Block device
  • Character device
  • Network device


Block device: accessed by block.  It supports the random access to the device. Usually can be accessed as the file system.
For example: hard disk. SSD.  CDROM,

Character device: accessed by sequence.  Character by character or byte by byte.  For example, keyboard, mouse, printer and pesdo terminals.

Network devices: Ethernet adapter. Accessed by socket.

There are some other devices in the system but they are not actual any physical device. they are called pseudo devices
eg: /dev/random ,urandom, /dev/zero, /dev/null,  /dev/stdin, /dev/stdout, /dev/loop

Shell – evaluation




Evaluation is widely used in SHELL programing. There are three types of evaluation:

  • File attribution: evaluate if the file is a block device, existing , writable…
  • String compare: if the strings are equalled.
  • Value testing: if the two values are equal, greater than, less than.

Here we will talk about the evaluation in detail.

File attribution evaluation:

-b
(block)testing if the file is exisitng and a block device
-c
(char)testing if the file is exisitng and a char device
-r
testing if the file is exisitng and read only
-w
testing if the file is exisitng and writable
-x
testing if the file is exisitng and execuatable
-d
testing if the file is a directory
-f
testing if the file is a normal file
-e
testing if the file is existing

Some samples are here:


Value testing:

n1 -eq n2
true if n1 equals n2
n1 -ne n2
true if n1 not equals n2
n1 -gt n2
true if n1 is greater than n2
n1 -lt n2
true if n1 is less than n2
n1 -ge n2
true if n1 is greater than or equal to n2

Some samples are here:

String compare:

s1 = s2
if the two strings are identical
s1 != s2
if the two strings are not identical
s1
if the string is existing

Some samples are here:

Also BASH have

  • [evaluation1] -a [evaluation 2] : AND connection
  • [evaluation1] -o [evaluation 2] : OR connection
  • !  [evaluation 2] : NOT operator.