Pages

Saturday, 26 October 2013

Performance modelling of a linux system using fork bomb


Today I will be showing you a simple way to measure the memory allocation capacity of the system.

Unlike in case of httpperf my method doesn't rely on the network based requests to load the system

I will be loading the system with processes by running a shell script in each of the guest operating systems(If the system under test is a server virtualized system) The shell scripts can be controlled remotely using telnet.

I would like to measure active memory, free memory, swap memory, inactive memory while loading the system with processes.

The idea here is to get all the required performance metrics from /proc/meminfo while forking processes. For example at one particular instance on my system
/proc/meminfo:



MemTotal:        2945376 kB
MemFree:          765960 kB
Buffers:          144004 kB
Cached:           993792 kB
SwapCached:            0 kB
Active:           979460 kB
Inactive:         995496 kB
Active(anon):     838076 kB
Inactive(anon):   178496 kB
Active(file):     141384 kB
Inactive(file):   817000 kB
Unevictable:          84 kB
Mlocked:              84 kB
SwapTotal:       6261756 kB
SwapFree:        6261756 kB
Dirty:               800 kB
Writeback:             0 kB
AnonPages:        837144 kB
Mapped:           213612 kB
Shmem:            179416 kB
Slab:              91864 kB
SReclaimable:      60272 kB
SUnreclaim:        31592 kB
KernelStack:        4000 kB
PageTables:        39688 kB
NFS_Unstable:          0 kB
Bounce:                0 kB
WritebackTmp:          0 kB
CommitLimit:     7734444 kB
Committed_AS:    4186924 kB
VmallocTotal:   34359738367 kB
VmallocUsed:      556904 kB
VmallocChunk:   34359177692 kB
HardwareCorrupted:     0 kB
AnonHugePages:         0 kB
HugePages_Total:       0
HugePages_Free:        0
HugePages_Rsvd:        0
HugePages_Surp:        0
Hugepagesize:       2048 kB
DirectMap4k:       63488 kB
DirectMap2M:     2942976 kB
=======

Also If we want to track any process, the folder /proc has details about each and every process running on the system.

Regarding loading the system:

There are two types of loads . Linear load  and Exponential load
In linear load, one process forks another process and waits for it to exit. The spawned process forks another process and waits for its child to exit. This keeps going on and on till the system eventually fails. To load the system with linear load we ran the following shell script:

#!/bin/bash
$0 &
wait

"$0 &" will run the same script in the background and 'wait' will make the current process to wait till the spawned process returns.

Similarly exponential load can be given by spawning 2 processes instead of one.
#!/bin/bash
$0 &
$0 &
wait

Collecting data:
The following code has to be embedded into the above script
# <epoch time> <PID> <Memory free> <swap free> <active memory> <inactive memory>

string=`date +%s`" "$$
i=`cat /proc/meminfo| grep "MemFree:"`
string=$string" "`expr "$i" : ".* \(.*\) kB"`
i=`cat /proc/meminfo| grep "SwapFree:"`
string=$string" "`expr "$i" : ".* \(.*\) kB"`
i=`cat /proc/meminfo| grep "Active:"`
string=$string" "`expr "$i" : ".* \(.*\) kB"`
i=`cat /proc/meminfo| grep "Inactive:"`
string=$string" "`expr "$i" : ".* \(.*\) kB"`
echo $string>>log
Sample output for linear load:
Sample output for exponential load:

Error removing file: Directory not empty

Something really weird happened today. I transferred some data to my external hard disk and for some reason I unplugged it from my comp without doing 'safely remove drive' (reason being I was lazy :P). Then after sometime I put it back on my laptop and tried removing the directory called Main_Game which I had created earlier. It said 'Error while deleting. Error removing file: Directory not empty'.

Then i tried doing that from terminal using 'rm -rf Main_Game'. Again it didn't work. It said rm: cannot remove 'Main_Game': Directory not empty


Then I thought there might be some process using that folder. So I restarted and tried again. It didn't work :(

Then I thought there might be some error in the filesystem. So I did force fsck.

$ sudo touch /forcefsck
$ sudo reboot

It successfully completed fsck. However the problem wasnt fixed

Then I did something which I should've tried long back and it worked!!

I simply deleted the folder (not force delete). The folder Main_Game was moved to recycle bin. I just deleted from there.

I dunno how this worked though :P

Saturday, 7 September 2013

Automatic log manager for Game of Thrones series.

I watch a lot of anime. When I started watching One Piece which had 500+ episodes, it was very hard for me to keep track of how many episodes I have seen already. So I used to keep a log file which always had the next episode's number and I used to manually update it whenever I watch an episode.

That was a good idea but not good enough :P. At least for awesome people like me doing work manually is too mainstream xD.
If you do all the work what is your computer there for???
So I wrote a script which automatically manages the log. And next time when I run the script it will continue from the place I stopped last time \m/. Now I am planning to start Game of Thrones TV series. People tell I'll like it because I am a big fan of Age of Empires and I love wars :D.

So now what I am planning to do is to automate viewing it just like I did for One piece. In the version of Game of Thrones which I have, each episode name has SxxExx in it. For example S02E09 is there in the file name of episode 9 in season 2. So using this I can iterate over series and inside that i can iterate over episodes.

Setup

Download the gist from here or copy it from here:

Step1

Place the script in the base folder which has folders of all the series. Make it executable:
$ chmod +x script.sh

Step2

create a file called "log" in the same folder. The log file contains current series number and episode number. For example if you are watching third episode of season 1, put 1:3 in that file and save it.

Running:

Just go that folder in terminal and do this:
$ ./script.sh

Now just enter the  number of episodes you want to watch in a stretch and enjoy!

Monday, 20 May 2013

Customizing linux terminal with powerline (powerline-shell)

Borded of how your terminal looks?
In the past I used to edit the bash superglobal $PS1 to make it look a littile better.
I found this awesome thing called powerline-shell on github which makes your terminal look so awesome. Not only it makes your terminal look beautiful it also helps us to visualize many things easily. Like errors, git stuff..etc
I took some time and modified it a little. Here is mine:

Download

How to get it?


  1.  Download powerline-bash.py from the link and place it in the home folder.
  2. Make it executable

    chmod +x ~/powerline-bash.py
  3. Then add the following lines to the file ~/.bashrc:
    function _update_ps1() {    export PS1="$(~/powerline-bash.py $?) " } export PROMPT_COMMAND="_update_ps1"
  4. Now patch the font. Download anonymous Pro-Powerline.ttf and open it to install it
  5. You are done!!! Now just open the terminal.


NOTE: If it doesn't work properly and prints some garbage elements then u have to patch the font you are using for your terminal from here

Saturday, 18 May 2013

Jarvis, at your sevice


Hello everyone! Its been a long time since I blogged. Today I will show you how to use 'Jarvis' which is an open source software which can be used to control your Linux system using your hand motion, gestures which was made as my Human Computer Interaction project. This is mainly an image processing based project developed using python.



Things u can do using Jarvis:


  1. The first thing you can do using Jarvis is control your mouse. You just need a colored object (preferably has color different from its background). So you can do things like draw in air!
  2. The second thing is that you can assign any gesture which is a combination of
    Left->Right, Right->Left, Top->Bottom, Bottom->Top to any command. So using this you can literally perform anything!!! The following are the things you can do by default:

  • Maximize/Minimize/Close current window
  • Go next and forward in PPT presentation
  • Page up and Page down
  • Switch window (Alt+tab)
  • Take screenshot
  • Shutdown/Suspend system
  • Mute and unmute
  • Open Calculator, File manager, Gedit


You can practically add anything else also. All you need to know is the command which does that and the equivalent of the gesture which you want to assign in the combination of Left->Right, Right->Left, Top->Bottom, Bottom->Top.

Getting dependencies:

Ubuntu:
$ sudo apt-get install python-opencv xdotool
Fedora:
$ sudo yum install python-opencv xdotool

Installation:

$ git clone https://github.com/alseambusher/jarvis.git
$ cd jarvis
$ ./install

Now you need to set the screen resolution of your screen. If your screen resolution is 1366x768 then skip this step.
$ gedit ~/.jarvis/config.py
change the value of variable RESOLUTION corresponding to your screen resolution.

Running:

Now simply open Jarvis from your Applications menu
OR
Do this:
$ cd ~/.jarvis
$ python main.py
Now click on Start Jarvis 

Add new gesture:

1. Go to settings from the File menu


2. Click on Add gesture from the File menu of settings


3. Suppose say that you want to add a gesture which opens terminal.
Say the gesture you wish to give is (Left to Right)->(Right to Left)->(Top to Bottom)->(Bottom to Top)
The command corresponding to open gnome terminal is 'gnome-terminal'

4. Fill the details and save it.


You are done!!!

Editing and deleting gestures are simple :P

How to use?

We need two different colored objects which are required to run. One the tracker and the other one is the flag!

  1. If the flag is not exposed then the gesture is disabled and Jarvis works as a mouse controller.
  2. When both tracker and flag are exposed the gesture begins. Perform the gesture using the tracker. Once the gesture is complete hide the flag. Jarvis then processes and analyses the gesture performed and checks for any matches from the existing database. If there is a match then it executes it!.

Customizing Tracker and Flag color:

By default the tracker is yellow color and flag is blue color.
You can change it by editing the config.py file

$ gedit ~/.jarvis/config.py

Change the min and max values of TRACKER_COLOR and GESTURE_COLOR corresponding to the HSV values of the color intended

By default these are the values:
TRACKER_COLOR={'MIN':[20,100,100],'MAX':[30,255,255]}
GESTURE_COLOR={'MIN': [108.0, 100, 10],'MAX': [118.0, 255, 255]}

Thank you. Dont forget to contribute to this open source project as there is a lot of scope for improvements. :)

Fork the project from here: https://github.com/alseambusher/jarvis

Thursday, 4 April 2013

Open with script in Gnome/Ubuntu

I always liked the feature open with script which was there in old ubuntu. I have no clue why they removed it. However as always in Linux there is always a way to do anything! Today I will show you a simple way( complex than before though ) to do it. Using this I was able to install Picasa Photo Viewer, Logism, yEd, MS Office..etc on my Ubuntu \m/

Step 1: Find MimeType of the target file (the file you want to open). You can find it in file properties


























Step2: Download this gist. And make it executable:

$ chmod +x open_with_script.sh

Step3: Then run the script and enter necessary details. For example I was trying to install yEd, an awesome Software Engineering Drawing tool. This is what I did:
NOTE that if the command is <command> <file name> enter as <command> %U





















Step4: This step is optional. This is to set font to the script. If you don't wanna do it, skip it. Open application called "Main Menu" or alacarte which comes by default in ubuntu. Then search for the script you just added and then set the font.

























Step5: Now just set the file to open with the script by default if necessary using file properties.


























Now you can simply open the file using yEd by default. So you are done!!! 

Saturday, 16 March 2013

Installing Turbo Assembler (TASM), Turbo Debugger (TD) on Ubuntu

Step 1
First we will install an windows emulator called dosbox.
sudo apt-get install dosbox

Step2

Download the packages for Turbo Assembler(tasm) Turbo Debugger(td)Create a directory for tasm in your home directory and extract files into that directory.If you are unable to extract type this in your terminal and try again
sudo apt-get install unrar

Step3

download this sample .asm file. Place the file in the tasm directory.

NOTE:  You can use your own asm file instead

Step4

Open dosbox( generally found in games sublist ). Now you have to mount the virtual c drive.
mount c /home/<username> eg: /home/alse

Step5

Now go to your TASM directory



Now test the test3.asm which you downloaded






Tuesday, 26 February 2013

Make STAR WARS message greet you when you open the terminal

I am a great fan of STAR WARS like many of you out there. So I decided to write a script which greets me with star wars message every time I open my Terminal to code.
Suppose say you are using Bash, when you open your terminal the file ~/.bashrc will run. Similarly if you are using Zsh => ~/.zshrc will run. So basically I can just put an echo statement in that to make it greet me every time I open my terminal. Today lets do something more interesting. Someting like this:


To get this you can just download this gist and add the contents in it to ~/.bashrc or ~/.zshrc or ~/.cshrc ..etc depending on which shell you are using. Or you can just copy the following and paste it in ~/.bashrc or ~/.zshrc or ~/.cshrc


Saturday, 16 February 2013

(98)Address already in use: make_sock: could not bind to address 0.0.0.0:443



I was setting up SSL on localhost to get https://localhost. I was successfully able to get the digital signature, sign it. But when i restarted apache2 I was getting this error:

(98)Address already in use: make_sock: could not bind to address 0.0.0.0:443

This means that port was already being listened. Hence at first I tried to kill the processes which are using that port. When this didn't work I tried this:

open /etc/apache2/ports.conf
Remove the line outside any <IfModule> tag which says Listen 443

Problem solved!!

Wednesday, 6 February 2013

Top 100 apps / software / libraries in Linux


Yesterday I took up the task of of listing out top hundred+ apps/softwares/libraries I use in Linux thinking that it might help people to make a list of what they have to install when they have newly installed linux.

         Editors
  1. vim - Vi improved
  2. gvim - Vim with GUI
  3. emacs
  4. kate
  5. geany - Good editor for many languages.
  6. bluefish - Good editor for PHP, Javascript, HTML, CSS
  7. code blocks
  8. eclipse
  9. netbeans
  10. pycharm 
  11. jedit

    Programming
  12. qt designer - Design in Qt
  13. pyqt4 - Python Qt library
  14. qt creater - Design and Code for Qt
  15. freeglut - OpenGL library
  16. filezilla - Good ftp client
  17. g++ - c/c++ compiler
  18. cmake - Cross-Platform Makefile Generator
  19. wireshark - Packet analyser
  20. unetbootin - startup disk creater
  21. apache2 - apache server
  22. mysql - mysql client/server
  23. php5 - php5 library
  24. php5-mysql - mysql library for php
  25. ipython - interactive python shell
  26. phpmyadmin - manage mysql databases
  27. open-jdk - java development kit
  28. git - revision control
  29. sqlite3 - database
  30. arduino - arduino programming
  31. linux-matlab - matlab for linux
  32. FontForge - create your ttf, ps..etc
  33. xampp

    General stuff
  34. unrar - extract files from rar archives
  35. ark - KDE archiving tool
  36. kchmviewer -  Windows CHM viewer for KDE
  37. gsnash-viewer - swf viewer
  38. virtualbox - x86 virtualization solution
  39. wine - wine is not an emulator
  40. deluge - torrent client
  41. linuxdcpp - Dc++ client
  42. ubuntu-tweak -tweak ubuntu settings
  43. compiz-config -change compiz settings
  44. k3b - CD/DVD buring tool
  45. brasero - CD/DVD buring tool
  46. nerolinux - CD/DVD buring tool
  47. playonlinux - Play on Linux
  48. q4wine -runs  GUI utility for wine applications and prefixes management.
  49. dropbox - cloud
  50. gnome-do - Launcher application
  51. gparted - partition manager
  52. empathy - GNOME multi-protocol chat and call client
  53. lightread - Google reader
  54. pidgin - IM client
  55. dolphin - File manager
  56. thunderbird - Mail manager
  57. cheese - webcam client
  58. evolution - calander
  59. adobe flash player
  60. axel - A light download accelerator for Linux
  61. proxychains - proxifier for linux
  62. ubuntu one - ubuntu cloud
  63. stellarium - astronomy
  64. byobu - cool terminal
  65. burg - customize how your bootloader looks
  66. dosbox
  67. docky - dock
  68. avant-window-navigator - MacOS X like panel for GNOME
  69. gnome-do - awesome searcher

    Update
  70. Conky

    Package Managers
  71. synaptic - package manager
  72. apt-fast - 'apt-get + axel' to download very fast
  73. aptitude - command line package manager
  74. pacman - package manager

    Browsers
  75. chomium-browser
  76. google-chrome-stable
  77. firefox
  78. konqueror - advanced file manager, web browser and document viewer

    Media editors
  79. picasa(on wine) - photo editor/viewer
  80. blender - 3D modelling
  81. gimp - photo editor
  82. audacity - audio editor
  83. inkscape - an SVG editing program
  84. dia - diagram editor (UML,Use Case,ER..etc)

    Update
  85. Kdenlive - awesome video editing software

    Media Players
  86. amarok
  87. banshee
  88. vlc
  89. mplayer
  90. Rhythmbox

    Interfaces
  91. unity
  92. gnome-shell 3
  93. kde plasma
  94. awesome
  95. openbox

    Games
  96. open Arena
  97. savage2
  98. assault cube
  99. nexuiz
  100. super tuxkart
  101. blobby volley
  102. hedgewars