Showing posts with label linux. Show all posts
Showing posts with label linux. Show all posts

Sunday, November 18, 2012

Running/Launching Linux/Android OS with  same kernel, Is it possible How to do?:

In Embedded/STB devices, Mostly they will be using the Linux OS.
Now they are moving to android. How it is possible for them to move to linux???

  over the Linux kernel, Some patches/changes are applied and it is called as android kernel. They are having separate branch also.
 To run android, Below Components involved:
    bootloader, kernel,android source code compiled binaries

    we have to compile kernel with target[ARM /x86] architecture. In the same way we have to compile android source code to the target architecture[x86/ARM].

   Initially the bootloader will loads kernel. Kernel will starts init process of android.

This init process will loads init.rc, init_board.rc scripts and also launches all the android services.

   The user can load linux/android OS with same kernel.

we can have a script to launch android/linux OS or based on user choice.

In launching an android script, we have to run android init processes in background;

android_launch.sh
  ./androidbin/init & # This init binary is generated from android source code.

  The target device should have all the android binaries.
        
 Linux also have the same script.
 
linux_launch.sh
   ./linuxbin/init &

   Linux source code also has init source code. This should be invoked if we want to launch the linux.This init process will launch all linux binaries.
The device should have all the linux source code compiled binaries.

Sunday, October 14, 2012

TO get/set an IP address from Linux over the socket:
 
int s;
    struct ifreq ifr = {};

    s = socket(PF_INET, SOCK_DGRAM, 0);

    strncpy(ifr.ifr_name, "eth0", sizeof(ifr.ifr_name));

    if (ioctl(s, SIOCGIFADDR, &ifr) >= 0)
        printf("%s\n",
          inet_ntoa(((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr));


ioctl call receives data from the kernel for SIOCGIFADDR for IP address.

In case of static IP address, we will set the IP address with ioctl( SIOCGIFADDR, socketDetails) call.
 
 
ioctl is the module which can be used for kernel/user or user to kernel communication. 
 
 For more, read Richard Steven's Unix Network Programming book
 
 
 

Thursday, October 04, 2012

How to detect IP address change in Linux:

http://stackoverflow.com/questions/579783/how-to-detect-ip-address-change-programmatically-in-linux

Friday, August 31, 2012


Background Process, Linux:

  if we want to run the process as background,we have to use & symbol.

   bash>./test.sh to run it as foreground service.

 To run it in background,

   bash>./test.sh &

How to run the process as service in linux: [Always up]:

  1) while linux system is in init process, shell files available in /etc/init.d got executed

whenever the system is up,  .profilerc or .bashrc or /etc/init.d/ scripts are executed.
Add your process to run in background

 add below line in your .bashrc or in any /etc/init.d/*.sh scripts
 
  ./MyService &


In Linux, From command prompt, if I want to do some bulk copy,usually I do like this:

 i) in one command prompt, I will perform copy operation
 ii)In another command prompt, I will do other work

We can do the same thing in single command prompt... How to do it ?

 i) run copy operation in background operation
 ii) Continue your work

  >cp bigFolder folderB &
   it will immediately returns to prompt,since copy operation is performed in background.
Next line, I can do any operation.
  >

 Once the copy operation is done, It will show below message in command prompt:

 2+1 cp Done.