Tuesday, 31 May 2011

How to mount an ISO image file as a filesystem in AIX


In AIX you "dd" the ISO file into a raw LV, then mount the LV as a filesystem.
Here are the steps for copying the ISO named "image.iso" into "/cd1iso", a JFS filesystem:
1. Create a filesystem with size slightly bigger than the size of the ISO image. Do NOT mount the filesystem:
# /usr/sbin/crfs -v jfs -g rootvg -a size=800M -m/cd1iso -Ano -pro -tno -a frag=4096 -a nbpi=4096 -a ag=8


2. Get the logical volume name associated with the new filesystem:
# lsfs | grep cd1iso (assume it is /dev/lv00)


3. dd the ISO image into rlv00 (raw lv00):
# dd if=image.iso of=/dev/rlv00 bs=10M


4. Alter /cd1iso stanza in /etc/filesystems => vfs=cdrfs and options=ro 


    /cd1iso:
            dev            = /dev/cd1_lv
            vfs             = cdrfs
            log             = /dev/loglv00
            mount           = false
            options         = ro
            account         = false


5. Mount the file system :
# mount /cd1iso


6. When finished, remove the filesystem:
# rmfs /cd1iso

Linux Kernek Panic Reboot


By default after a kernel panic Linux just waits there for a system administrator to hit the restart or powercycle button.  This is because of the value set on "kernel.panic" parameter.


[root@linux23 ~]# cat /proc/sys/kernel/panic
0
[root@linux23 ~]# sysctl -a | grep kernel.panic
kernel.panic = 0
[root@linux23 ~]#


To disable this and make the Linux OS reboot after a kernel panic, we have to set an integer N greater than zero to the paramter "kernel.panic", where "N" is the number of seconds to wait before a automatic reboot.  For example , if you set N = 10 , then the system waits for 10 seconds before automatic reboot. To make this permanent, edit /etc/sysctl.conf and set it.


[root@linux23 ~]# echo "10" > /proc/sys/kernel/panic
0
[root@linux23 ~]# grep kernel.panic /etc/sysctl.conf
kernel.panic = 10
[root@linux23 ~]#

Monday, 23 May 2011

HOW WILL WORK HASHMAP IN JAVA


"Have you used HashMap before" or "What is HashMap? Why do we use it “ 


Almost everybody answers this with yes and then interviewee keep talking about common facts about hashMap like hashMap accpt null while hashtable doesn't, HashMap is not synchronized, hashMap is fast and so on along with basics like its stores key and value pairs etc.
This shows that person has used hashMap and quite familier with the funtionalities HashMap offers but interview takes a sharp turn from here and next set of follow up questions gets more detailed about fundamentals involved in hashmap. Interview here you and come back with questions like


"Do you Know how hashMap works in Java” or 
"How does get () method of HashMap works in Java" 


And then you get answers like I don't bother its standard Java API, you better look code on java; I can find it out in Google at any time etc.
But some interviewee definitely answer this and will say "HashMap works on principle of hashing, we have put () and get () method for storing and retrieving data from hashMap. When we pass an object to put () method to store it on hashMap, hashMap implementation calls
hashcode() method hashMap key object and by applying that hashcode on its own hashing funtion it identifies a bucket location for storing value object , important part here is HashMap stores both key+value in bucket which is essential to understand the retrieving logic. if people fails to recognize this and say it only stores Value in the bucket they will fail to explain the retrieving logic of any object stored in HashMap . This answer is very much acceptable and does make sense that interviewee has fair bit of knowledge how hashing works and how HashMap works in Java.
But this is just start of story and going forward when depth increases a little bit and when you put interviewee on scenarios every java developers faced day by day basis. So next question would be more likely about collision detection and collision resolution in Java HashMap e.g 


"What will happen if two different objects have same hashcode?”


Now from here confusion starts some time interviewer will say that since Hashcode is equal objects are equal and HashMap will throw exception or not store it again etc. then you might want to remind them aobut equals and hashCode() contract that two unequal object in Java very much can have equal hashcode. Some will give up at this point and some will move ahead and say "Since hashcode () is same, bucket location would be same and collision occurs in hashMap, Since HashMap use a linked list to store in bucket, value object will be stored in next node of linked list." great this answer make sense to me though there could be some other collision resolution methods available this is simplest and HashMap does follow this.
But story does not end here and final questions interviewer ask like 


"How will you retreive if two different objects have same hashcode?” 


 Hmmmmmmmmmmmmm
Interviewee will say we will call get() method and then HashMap uses keys hashcode to find out bucket location and retreives object but then you need to remind him that there are two objects are stored in same bucket , so they will say about traversal in linked list until we find the value object , then you ask how do you identify vlaue object because you don't value object to compare ,So until they know that HashMap stores both Key and Value in linked list node they won't be able to resolve this issue and will try and fail.


But those bunch of people who remember this key information will say that after finding bucket location , we will call keys.equals() method to identify correct node in linked list and return associated value object for that key in Java HashMap. Perfect this is the correct answer.


In many cases interviewee fails at this stage because they get confused between hashcode () and equals () and keys and values object in hashMap which is pretty obvious because they are dealing with the hashcode () in all previous questions and equals () come in picture only in case of retrieving value object from HashMap.
Some good developer point out here that using immutable, final object with proper equals () and hashcode () implementation would act as perfect Java HashMap keys and improve performance of Java hashMap by reducing collision. Immutablity also allows caching there hashcode of different keys which makes overall retreival process very fast and suggest that String and various wrapper classes e.g Integer provided by Java Collection API are very good HashMap keys.


Now if you clear all this java hashmap interview question you will be surprised by this very interesting question "What happens On HashMap in Java if the size of the Hashmap exceeds a given threshold defined by load factor ?".
 Until you know how hashmap works exactly you won't be able to answer this question. 
if the size of the map exceeds a given threshold defined by load-factor e.g. if load factor is .75 it will act to re-size the map once it filled 75%. Java Hashmap does that by creating another new bucket array of size twice of previous size of hashmap, and then start putting every old element into that new bucket array and this process is called rehashing because it also applies hash function to find new bucket location. 


If you manage to answer this question on hashmap in java you will be greeted by "do you see any problem with resizing of hashmap in Java" , you might not be able to pick the context and then he will try to give you hint about multiple thread accessing the java hashmap and potentially looking for race condition on HashMap in Java. 


So the answer is Yes there is potential race condition exists while resizing hashmap in Java, if two thread at the same time found that now Java Hashmap needs resizing and they both try to resizing. on the process of resizing of hashmap in Java , the element in bucket which is stored in linked list get reversed in order during there migration to new bucket because java hashmap doesn't append the new element at tail instead it append new element at head to avoid tail traversing. if race condition happens then you will end up with an infinite loop. though this point you can potentially argue that what the hell makes you think to use HashMap in multi-threaded environment to interviewer :) 


I like this question because of its depth and number of concept it touches indirectly, if you look at questions asked during interview this HashMap questions has verified 
Concept of hashing 
Collision resolution in HashMap
Use of equals () and hashCode () method and there importance?
Benefit of immutable object?
race condition on hashmap in Java
Resizing of Java HashMap


Just to summararize here are the answers which does makes sense for above questions


How HashMAp works in Java


HashMap works on principle of hashing, we have put () and get () method for storing and retrieving object form hashMap.When we pass an both key and value to put() method to store on HashMap, it uses key object hashcode() method to calculate hashcode and they by applying hashing on that hashcode it identifies bucket location for storing value object.
While retrieving it uses key object equals method to find out correct key value pair and return value object associated with that key. HashMap uses linked list in case of collision and object will be stored in next node of linked list.


Also hashMap stores both key+value tuple in every node of linked list.


What will happen if two different HashMap key objects have same hashcode?


They will be stored in same bucket but no next node of linked list. And keys equals () method will be used to identify correct key value pair in HashMap.


In terms of usage HashMap is very versatile and I have mostly used hashMap as cache in electronic trading application I have worked . Since finance domain used Java heavily and due to performance reason we need caching a lot HashMap comes as very handy there.

how to get command in unix



  1. Runnig the last executed command in unix:

!find 
This will repeat the last find command executed. It saves lot of time if you re searching for something and you need to execute same command again and again. In fact "!" can be used with any command to invoke previous run of that command.
   2.   Finding files which has been modified less than one day in Unix:
find . -mtime -1


This is my favorite while looking out some issue just to check which files have been modified recently which could be likely cause of  issue, believe me it helps a lot and many a times gives you enough hint of any problem due to intended or unintended file change.


3. List all the files and directories in the box which holds the 777 permission in Unix?
find . -perm 777 –print


I use this command to find out all the executable files , you can also modify it to find all the read only files or files having write permission etc by changing permissions e.g. to find all read only files in current directory : find . –perm 555
Here "." or period denotes current directory. You can replace it with any directory you want.


4. How to do case insensitive search using find command in Unix? Use option “-i" with name, by default find searches are case sensitive.
find . –iname "error" –print 




5. How to delete temporary files using find command in Unix?
find . -name *.tmp -print | xargs rm –f


Use of xargs along with find gives you immense power to do whatever you want with each search result. See another example below


6. How to find all text file which contains word Exception using find command in Unix ?
find . –name *.txt –print | xargs grep “Exception” 


find . –name *.java –print | xargs grep “MemoryCache”, this will search all java files starting from current directory for word "MemoryCache".




7. Finding files only in current directory not searching on sub directories:
While using find command I realized that some time I only need to find files and directories that are new , only in the current directory so I modified the find command as follows.


find . -maxdepth 1 -type f -newer first_file


Another way of doing it is below:


find . -type f -cmin 15 -prune


Means type file, last modified 15 minutes ago, only look at the current directory. (No sub-directories)




8. Find all files in current directory and subdirectory, greater than some size using find command in Unix:
find . -size +1000c -exec ls -l {} \; 


Always use a c after the number, and specify the size in bytes, otherwise you will get confuse because find -size list files based on size of disk block. to find files using a range of file sizes, a minus or plus sign can be specified before the number. The minus sign means "less than," and the plus sign means "greater than." Suppose if you want to find all the files within a range you can use find command as below


find . -size +10000c -size -50000c -print


This example lists all files that are greater than 10,000 bytes, but less than 50,000 bytes: 


9. Find files which are some days old and greater than some size in Unix. Very common scenario where you want to delete some large old files to free some space in your machine. You can use combination of "-mtime" and "-size" to achieve this.


find . -mtime +10 -size +50000c -exec ls -l {} \; 


This command will find which are more than 10 days old and size greater than 50K.


10. You can use "awk" in combination of find to print a formatted output e.g. next command will find all of the symbolic links in your home directory, and print the files your symbolic links points to:


find . -type l -print | xargs ls -ld | awk '{print $10}'


"." says starts from current directory and include all sub directory
"-type l" says list all links


Hope you find this useful , please share how you are using find commands and we can benefit from each others experience and work more efficiently in unix.

Sunday, 1 May 2011

IT PUBLICATIONS


  1. http://www.32bitsonline.com/  A LARGE AMOUNT OF LINUX INFORMATION AVAILABLE HERE
  2. http://xrds.acm.org/  ORIENTAL FRAME WORK DEVELOPING ,EXTENSIBLE IMAGE INPUT AND OUT PUT LIBRARIES AVAILABLE HERE.
  3. http://www.advisor.com/  ADVICE ABOUT E-BUSINESS AND ENTERPRISE DEVELOPMENT STRATEGIES,TECHNOLOGIES.
  4. http://www.bbc.co.uk/news/science_and_environment/  TECHNOLOGY NEWS FROM BBC
  5. http://www.crn.com/   PROVIDERS FOR INFORMATION AND TECHNOLOGY SERVICES

IT BOOKS SITES


  1. http://www.bookpool.com/   ITS TECHNICAL BOOK STORE
  2. http://www.halfpricecomputerbooks.com/  LOW PRICE COMPUTER BOOKS
  3. http://www.technologybooks.com/      NETWORKING RELATED BOOKS AVAILABLE HERE
  4. http://www.wkmn.com         INTERNET WORKING  TOPIC BOOKS AVAILABLE HERE
  5. http://www.standardsdirect.org/  GOOD SITE FOR DOWNLOADING MAJOR INTERNATIONAL STANDARDS