Wednesday, 12 February 2014

How to mount Windows 7 folder into guest Ubuntu 12.04 directory




Well,Hope you doing well.

When you are working on VM Box and Window machine simultaneously then usually you do share some stuff between Window and Virtual Box like some project file or other files/directroy which are reside in your Window machine .
Sometime you upload files intoVMBox using some external software which is tedious task.

Here, do some easy step's that make your easier to switch/mount window file into VMBox or vice-verse.


Step 1.

Open VM Virtualbox and Click on setting, select "Shared Folder" from left panel and add share folder to which you want to share into VM Box.At last ok with done.

Here Share folder name is D:\Shared



Steps-2: (VM Box Ubuntu Side )


Open a terminal and run following command one by one

$ sudo apt-get install dkms

Need to reboot your VM Virtaul Box then
$ sudo /sbin/reboot   

$sudo apt-get install virtualbox-ose-guest-x11

 Create a shared folder under /usr/work/ directory.


$mkdir shared_work

$sudo mount -t vboxsf Shared ./shared_work



I hope this stuff will help you.
Thanks
--------

Installing Guest Additions for Linux

  1. Open VirtualBox, and start your UbuntuVB virtual machine. After logging into Ubuntu with your user account, open a terminal window, and type sudo apt-get install dkms, followed by Enter. Then follow the instructions on screen to install the DKMS package. Once installed, close the terminal window.
  2. Select Devices | Install Guest Additions from the VirtualBox menu:
  3. VirtualBox 3.1: Beginner's Guide
  4. VirtualBox will mount the Guest Additions ISO file on your virtual machine's CD/DVD-ROM drive, and theVBOXADDITIONS icon will appear on your desktop.
  5. Now open a terminal window, and type cd /media/cdrom followed by Enter to change to the CD-ROM directory containing the Guest Additions. Then type sudo sh ./VBoxLinuxAdditions-x86.run, and pressEnter to start installing the VirtualBox Guest Additions on your virtual machine. When finished, the setup program will ask you to restart your Ubuntu VM.
    If you're running a 64-bit Linux guest, replace VBoxLinuxAdditions-x86.run with VBoxLinuxAdditions-amd64.run.
  6. Close the terminal window, restart your virtual machine, and wait for Ubuntu to boot up. Once is has finished booting up, a VirtualBox - Information dialog will appear to tell you that your guest operating system now supports mouse pointer integration.
  7. Enable the Do not show this message again, and click on the OK button to continue. Now you'll be able to move your mouse freely between your virtual machine's area and your host machine's area! You'll also be able to resize your virtual machine's screen, and it will adjust automatically!

Wednesday, 5 February 2014

Thread Synchronization - Monitors


Monitors

A monitor is like a building that contains one special room that can be occupied by only one thread at a time. The room usually contains some data. From the time a thread enters this room to the time it leaves, it has exclusive access to any data in the room. Entering the monitor building is called "entering the monitor." Entering the special room inside the building is called "acquiring the monitor." Occupying the room is called "owning the monitor," and leaving the room is called "releasing the monitor." Leaving the entire building is called "exiting the monitor." 

A graphical depiction of the kind of monitor used by a Java virtual machine is shown in Figure 20-1. This figure shows the monitor as three rectangles. In the center, a large rectangle contains a single thread, the monitor's owner. On the left, a small rectangle contains the entry set. On the right, another small rectangle contains the wait set. Active threads are shown as dark gray circles. Suspended threads are shown as light gray circles.






Figure 20-1 also shows several numbered doors that threads must "pass through" to interact with the monitor. When a thread arrives at the start of a monitor region, it enters the monitor via the leftmost door, door number one, and finds itself in the rectangle that houses the entry set. If no thread currently owns the monitor and no other threads are waiting in the entry set, the thread passes immediately through the next door, door number two, and becomes the owner of the monitor. As the monitor owner, the thread continues executing the monitor region. If, on the other hand, there is another thread currently claiming ownership of the monitor, the newly arrived thread must wait in the entry set, possibly along with other threads already waiting there. The newly arrived thread is blocked and therefore doesn't execute any further into the monitor region.

Figure 20-1 shows three threads suspended in the entry set and four threads suspended in the wait set. These threads will remain where they are until the current owner of the monitor--the active thread--releases the monitor. The active thread can release the monitor in either of two ways: it can complete the monitor region it is executing or it can execute a wait command. If it completes the monitor region, it exits the monitor via the door at the bottom of the central rectangle, door number five. If it executes a wait command, it releases the monitor as it travels through door number three, the door to the wait set.

The Java virtual machine offers two kinds of notify commands: "notify" and "notify all." A notify command selects one thread arbitrarily from the wait set and marks it for eventual resurrection. A notify all command marks all threads currently in the wait set for eventual resurrection.

To a great extent, the manner in which a Java virtual machine implementation selects the next thread from the wait or entry sets is a decision of individual implementation designers. For example, implementation designers can decide how to select: o a thread from the wait set given a notify command o the order to resurrect threads from the wait set given a notify all command o the order to allow threads from the entry set to acquire the monitor o how to choose between threads suspended in the wait set versus the entry set after a notify command. You might think it would make sense to implement entry set and wait sets as first-in-first-out (FIFO) queues, so that the thread that waits the longest will be the first chosen to acquire the monitor. Alternatively, it might make sense to have ten FIFO queues, one for each priority a thread can have inside the Java virtual machine. The virtual machine could then choose the thread that has been waiting the longest in the highest priority queue that contains any waiting threads. Implementations may take approaches such as these, but you can't depend on it. Implementations are free to implement the entry and wait sets as last-in-first-out (LIFO) queues, to select lower priority threads before higher priority threads, or to do anything else that may not seem to make sense. In short, implementations are free to select threads in an arbitrary manner that defies analysis and yields surprising orderings.



Monday, 20 January 2014

Linux Command



Linux Commands






Find Command 

## To search for files in /target_directory and all its sub-directories, that have been modified in the last 60 minutes:

    $ find /target_directory -type f -mmin -60

## To search for files in /target_directory and all its sub-directories, that have been modified in the last 2 days:

    $ find /target_directory -type f -mtime -2

## To search for files in /target_directory and all its sub-directories no more than 3 levels deep, that have been modified in the last 2 days:

    $ find /target_directory -type f -mtime -2 -depth -3

## You can also specify the range of update time. To search for files in /target_directory and all its sub-directories, that have been modified in the last 7 days, but not in the last 3 days:

    $ find /target_directory -type f -mtime -7 ! -mtime -3

## To search for files in /target_directory (and all its sub-directories) that have been modified in the last 60 minutes, and print out their file attributes:

    $ find /target_directory -type f -mmin -60 -exec ls -al {} \;
    $ find /target_directory -type f -mmin -60 | xargs ls -l



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

## It return files which size is greater than 50M

find . -size +50000000c -exec ls -lh {} \;

## It return files which extension are .java and end with other character

find . -type f -name "*.java*" -print


Change Shell by Cmd 
   
##First, find out available shell list:

    $ less /etc/shells
   
##Now change your shell name to /bin/tcsh:

    $ chsh -s /bin/tcsh
   
##When promte for password, type your own password. If you just type chsh command, it will prompt for shell name interactively:

    $ chsh

Owner Ship Cmd on File System 

    $chmod u+x <filename>
    $chmod uog+xwr <filename>
           u : User           
           g : Group   
           o : Other
           ---------
           r : Read  : 4
           w : Write : 2
           x : Execute : 1
    $chmod 660 <Filename> // owner group other

    $chmod 751 tech

    $chmod u=rwx, g=rx, o=x tech
   
    <chown> change ownership of file system.


##As the owner, jim can use the chmod command to permit or deny other users access to program.c.

    $chown jim program.c


##To change the owner and group of all files in the directory /tmp/src to owner john and group build:

    $chown -R john:build /tmp/src 

   
Linux Version Info

## see your current Linux kernel version:

    $ uname -r
    $ uname -mrs

## To print all information, enter:

    $ uname -a

## see Linux version info:

    $ cat /proc/version

## Here is another output from my Debian based serve

    $ lsb_release -a
   
 Process Command line Info

## Display a tree of processes

    $ pstree

## Dynamic real-time view of a running system

    $ top

## Display all running process:

    $ ps aux | less

## Print a process tree using ps

    $ ps -ejH
    $ ps axjf

## Get info about threads

    $  ps -eLf

## Get security info

    $ ps -eo euser,ruser,suser,fuser,f,comm,label
    $ ps axZ
    $ ps -eM

## Save Process Snapshot to a file

    $ top -b -n1 > /tmp/process.log
    <<you can email result to yourself>>

    $ top -b -n1 | mail -s 'Process snapshot' you@example.com


Sunday, 5 January 2014

how-to-remove-duplicates-from-array-java-without-collection-API


In this program, we have not used any collection class to remove duplicates, In this example, we are removing duplicates elements from array and copying them into newly result array.


1:  import java.util.Arrays;  
2:  /**  
3:   * @author Ajaykumar.gupta  
4:   *  
5:   */  
6:  public class RemoveDublicateElements {  
7:      /**  
8:       * Suppose let have a arrays of integer elements.  
9:       */  
10:      private static int[] array = { 1, 2, 3, 4, 2, 4, 5, 6, 7, 1, 3, 5, 9, 8, 7,  
11:              6, 7, 8, 9, 0, 8, 6, 5, 0, 5, 4, 3, 2, 5, 6, 0, 1, 2, 3, 4, 5, 6 };  
12:      public static void main(String args[]){  
13:          int[] values = removeDublicate(array);  
14:          for(int i=0; i < values.length ;i++ ){  
15:              System.out.print(values[i]+" ");  
16:          }  
17:      }  
18:      private static int[] removeDublicate(int[] array){  
19:          /**  
20:           * Sort Array elements first.  
21:           */  
22:          Arrays.sort(array);  
23:          // Allocated a new array with same size.  
24:          int []result= new int[array.length];  
25:          // Assigned a first element into a previous variable.  
26:          int previous = result[0];  
27:          // Assigned a smallest elements into Array zero position.  
28:          result[0] = previous;  
29:          int num = 1;  
30:          for(int i=1; i <array.length;i++){  
31:              int ch = array[i];  
32:              // Logic is applied for removed duplicate elements and assigned to result array  
33:              if(previous != ch){  
34:                  result[num++] = ch;  
35:              }  
36:              previous = ch;  
37:          }  
38:          // Removed Blank space(Zero) and copy exect size of array and return it to caller.  
39:          return Arrays.copyOf(result, num);  
40:      }  
41:  }  

Output : 0 1 2 3 4 5 6 7 8 9