Friday, June 24, 2011

Unix Load Average

When you issue one of these commands "w, top, or uptime", you would find a parameter called Load Average with 3 fields; I thought it has sth related to a CPU utilization but after got asked about it in a Google interview, it seems to have more than that.

Here is uptime output:
14:34:03 up 10:43, 4 users, load average: 0.06, 1.11, 0.09

This means that the CPU is 6% underloaded in the last minute and overloaded by 11% in the last 5 minutes and is underloaded with 9% in the last 15 minutes.

For multiple CPUs architecture, it means that this number of processes can be scheduled on these CPUs.

This is useful for capacity planning and performance monitoring of CPU and the running processes.

It has been considered that 3 is a good threshold value (From O'Reilly UNIX Power Tools) .

Friday, June 3, 2011

DataTypes in Programming Languages

-statically typed language:
A language in which types are fixed at compile time. Most statically typed languages enforce this by requiring you to declare all variables with their datatypes before using them. Java and C are statically typed languages.

-dynamically typed language:
A language in which types are discovered at execution time; the opposite of statically typed. VBScript and Python are dynamically typed, because they figure out what type a variable is when you first assign it a value.

-strongly typed language:
A language in which types are always enforced. Java and Python are strongly typed. If you have an integer, you can't treat it like a string without explicitly converting it.

-weakly typed language:
A language in which types may be ignored; the opposite of strongly typed. VBScript is weakly typed. In VBScript, you can concatenate the string '12' and the integer 3 to get the string '123', then treat that as the integer 123, all without any explicit conversion.

So Python is both dynamically typed (because it doesn't use explicit datatype declarations) and strongly typed (because once a variable has a datatype, it actually matters).

* from DiveintoPython.org

Wednesday, December 15, 2010

Processor Revolution



Fig. Nvidia Tegra SoC second generation " Tegra 2"
The revolution of Smart Mobile Phone Processors.
More than 1GHz Dual Core Processor

Wednesday, November 10, 2010

Combination and Integration

-CORBA "Common Object Request Broker Architecture": briefly, is a standard to make objects of different programming languages and make them communicate together if they are in the same machine or many machines.

-MPI "Message Passing Interface": is an API that would allow distributed apps to run as a single app.

-SWIG: is a tool used to interface and generate bindings of C/C++ to variety of programming languages such as Java and Python. A special tool for python is called SPI.

Tuesday, November 2, 2010

How to remove extra menu items in grub boot loader

When I have installed updates for my ubuntu linux, the kernel image also updated so I found several images of linux kernel at my machine and also many menu items at the boot loader depending on the number of versions linux kernels in my machine. This was annoying for me.
Then I prefer to have only two menu items at boot loader: one for the current version of linux and the other for windows.

Procedure:
--Write down the menu items you do not like to see in grub. At my case "Ubuntu, with Linux 2.6.32-25-generic (recovery mode)" and "Ubuntu, with Linux 2.6.32-25-generic".
--Delete the following from file /boot/grub/grub.cfg

menuentry 'Ubuntu, with Linux 2.6.32-25-generic' --class ubuntu --class gnu-linux --class gnu --class os {
recordfail
insmod ext2
set root='(hd0,2)'
search --no-floppy --fs-uuid --set 039c3fcd-6448-4da2-9a2c-4ce29e4f7926
linux /boot/vmlinuz-2.6.32-25-generic root=UUID=039c3fcd-6448-4da2-9a2c-4ce29e4f7926 ro quiet splash
initrd /boot/initrd.img-2.6.32-25-generic
echo Abuselim
}
menuentry 'Ubuntu, with Linux 2.6.32-25-generic (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os {
recordfail
insmod ext2
set root='(hd0,2)'
search --no-floppy --fs-uuid --set 039c3fcd-6448-4da2-9a2c-4ce29e4f7926
echo 'Loading Linux 2.6.32-25-generic ...'
linux /boot/vmlinuz-2.6.32-25-generic root=UUID=039c3fcd-6448-4da2-9a2c-4ce29e4f7926 ro single
echo 'Loading initial ramdisk ...'
initrd /boot/initrd.img-2.6.32-25-generic
}

3. Go to /boot and delete files with "2.6.32-25" string
4. reboot and find results ;-)

By aselims

Sunday, October 24, 2010

Stack and Heap Snippet

*Stack allocation
Image myImage;
myImage.SetAllPixels(ClearColor);

*Heap allocation
Image *imagePtr;
imagePtr = new Image();
imagePtr->SetAllPixels(ClearColor);

...

delete imagePtr;

Stack allocation: Constructor and destructor called automatically when the function is entered and exited.
Heap allocation: Constructor and destructor must be called explicitly.

Wednesday, October 20, 2010

How to know if your PC is 64 bit?

Description:
There is a processor flag called lm "long mode" means this processor is a 64-bit capable.
Procedure:
cat proc/cpuinfo
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe nx lm constant_tsc arch_perfmon pebs bts pni dtes64 monitor ds_cpl est tm2 ssse3 cx16 xtpr pdcm lahf_lm ida

note: Also another flag called vmx that tells this processor supports virtualization Technology for Intel processors.