code coverage for c program on linux

April 6, 2011 at 6:25 PM | Posted in Uncategorized | 1 Comment

The setup used here is FC12 linux machine.

Here we will use  “gcov” tool for code coverage.  In addition with gcov, we will use “lcov” and “genhtml” for  output in HTML formatt. To know more about these tools and options you can refer their man pages.

1) First install these packages: gcov, lcov and genhtml. You can install from sources or yum.

2) To test the code coverage for a c source program, the program must be compiled with  “-fprofile-arcs” and -”ftest-coverage” flags.

$ gcc -fprofile-arcs  -ftest-coverage test.c – o test

3) Then run the program.

$  ./test

It will create 2  additional file with extensions gcno and gcda. In this example it should be test.c.gcno and test.gcda

4) Then use lcov tool to generate html output file.

$ lcov –directory . -c -o test.info . Here test.info is output file.

5) Using genhtml, generate hrtml file from lcov data

$ genhtml test.info

It will generate few html files. You can view the html files using broweser or htmlview command

$ htmlview index.html

How to run remote X application on Linux

June 16, 2010 at 1:05 PM | Posted in Uncategorized | Leave a comment

The X Window System (commonly X or X11) is  a application and network protocol which provides a graphical user interface (GUI) for network computers.You’re using two computers.

You’re using the X window system of the first to type to and look at. You’re using the second to do some important graphical work. You want the second to show its output on the display of the first. The X window system makes this possible. Here, the first computer is X server and second computer is X client.  X server typically runs on user’s console

Configuring X server and client

The following configuration is working fine for Fedora Core 8. Different distributions may have different configurations and settings.

Configuring X server

1) Install X11 package, if its not already installed

#rpm -qa |grep X11

if not installed, install through yum or sources. Using yum,

#yum install xorg-x11*

2) X server should be running on server machine.

#ps aux |grep X

If it not running, start it manually.

#X &

3) X server should  listen on port 6000.

#netstat -an |grep 6000

if its not listening, check whether 6000 port is open or not

#nmap -p 6000

If not open, open is using command

# nc -l 6000

3) Allow Xclient to access Xserver

#xhost +

This will allow Xclient from any host to connect to Xserver. You can add paticular IP also, instead of allowing everyone (xhost +192.168.16.1)

4) Add the following line DisallowTCP=false under security field in /etc/gdm/custom.conf file. After adding, the part of the file should look like

[security]
DisallowTCP=false

Restat the gdm service

#gdm-restart

Configuring X client

logon to Xclient through ssh. then set the DISPLAy environment variable

#export DISPLAY=<yourXserverIP>:0.0

Now, if you run any GUI application, it should display on Xserver machine.

You can try,

#xterm&

or your any GUI application


Why One is 1 and Two is 2??….

May 5, 2010 at 11:20 AM | Posted in time pass | Leave a comment

Why One is 1 and Two is 2??….

Shayris

November 30, 2009 at 10:58 PM | Posted in shayri | Leave a comment
Tags:

Garmiye hasrate nakaam se jal jate hein,
hum
Chiragon ki tarha shaam se jal jate hein..

Shama jis aag mai jali hai numayesh ke liye,
hum usi aag mai gum naam se jal jate hein..

Jab bhi aata hai tera naam mere naam ke saath,
jane kyun log mere naam se jal jate hein…

na tha kuchch to KHuda tha, kuchch na hota to KHuda hota
duboya mujhko hone ne, na hota maiN to kya hota ?

Unhe Yeh Shikayat Hai Humse Ki,
Hum Har Kissi Ko Dekh Kar muskurate hain,

Nashamjh Hain woh kya jane,
Hame to har Chehre main woh hi nazr ate hain.

Jis shaam mein mere lab per aapka naam na aaye,
Khuda kare ki kabhi aisi shaam na aaye,
Ae jaane wafa yeh kabhi mumkin nahin ki,
Afsaana likhoon aur aapka naam na aaye.

Ahmed Faraz Shayari

Kuch muhabat ka nasha tha pehle hm ko Faraz.
Dil jo tota to nashe se muhabat ho gai.

———————————-
Yeh wafa to un dinon ki baat hay “Fraaz”
Jab makaan kachy or log sachay hoa krty thy……

———————————-
Kon data ha umar bhar ka sahara aay Faraz….
LOG tu JANAZAY man bhi kandhay badaltay rahtay hein….

———————————-
“Kis ki Kya majal thi jo koi Hum ko kharid sakta”,,,
Faraz,..
“Hum to khud hi Bik gaey kharidar dekh k”…

———————————-
‘”Ham na badlein gay waqt ki raftaar kay sath,,,
‘”Faraz”‘
Ham jab b milen gay andaz purana hoga…’”.

———————————-
“Tera Na Ho Saka To Mar Jaon Ga Faraz.
Kitna Khobsurat Wo Jhoot Bolta Tha”.

———————————-
Wo Bewafa na tha youn hi badnaam ho gya,,,,
Faraz..,…
Hazaron chaheny waly thy kis kis say wafa karta……
-

———————————
Hum pe faqat ilzaam k hum hain zuban daraz…….
hum ne to bus kaha tha hamain tum se piyar hai….!
———————————-
Zindagi to apnay hi Qadmon pe chalti hai Faraz..,
Auron k $aharay to Janazay utha kartay hain..!
-
———————————
Yahee soch kar us ki har baat ko sach mana hay
“FARAZ”~
K itnay khubsoorat Lub jhoot kesay bolain gay..~
-
———————————
Bari Mushkil se Sulaaya tha Khud Ko FARAZ Main ne Aaj…!
Apni Aaankon Ko Tare Khuwaab Ka Laalach Day Ker…..!
-
———————————
Be nàam zىndagى ki haqeeqat na poochhiye ‘FARAZ’,
Kuch pur khaloٍs log thay,barbàd kr gaey…….
-
———————————
Wo roz dekhta hai dubtay huay suraj ko faraz.
Kash mai b kisi shaam ka manzir hota….!
———————————-
Main us k Haathon me tha
Tute hue Sheeshe ki trha “Faraz”,
Bari Umeed thi k bikhrne nhi dega.
Bus giraya kuch is Ada se k
Simatne ki Aaas hi na rahi.

——————————–
Bara naaz tha un ko apne parde pe faraz…
Kal raat woh khawab me sar-e-aam chale aaye…
———————————-
Kabhi Kabhi Wo Mujhe itna Yad Aata He Faraz
Me Zid Me Aa K Usay Yaad B Nahi Karta

——————————–
Mere kahny sy na paband-e-wafa ho jana,
dil na many to kse waqt juda ho jana,
na chaho jan se ziada kise ko
Faraz,
tum ny dekha nahen bandon ka khuda ho jana.
—–
—————————–
Tum is shehar k khuloos se waqif nahi FARAZ
Ye to Mohsin ko bhi sar-e-aam saza daitay hain!

————————————

wo roye ga meri mayyat per mujhse is tarha lipat kar faraaz …!

agar yeh pehle pata hota to kab ke mar gaye hote …

————————————

 Na janE KaB Se Ho GayE ItNay ShiDDat PasaNd HaM ?FArAz !
JaB Tak ZakhaM Na KhAyEn tAssalEE nAhi hoTi ?

__________
Us Shaks Ko To Bichadeny Ka Saleka Nahi ” FARAZ”
Jatay Hoe Khud KO Mere Pass Chor Gaya .

________
Apni Nakaami ka EK Yeh Bhi Sabab Hai FaRaZ.
Cheez Jo Mangte Hain Sb Se Juda Mangte Hain.

________
Ye dunya gum to deti hai shareek-e-gum nahi hoti
kisi k door jany se mohabat kam nahi hoti

_____
Ab maayos q ho us ki bewafai pe Faraz?
tm khud hi to kehty thy k wo sab se juda hai

____
Asaan nahin aabad karna ghar mohabat ka
ye unka kaam hai jo zindagi barbad karty hain

________
Usne mujh chor dia to kia hua Faraz
Mane bhi to chora tha sara jahan us k liye

________
Tujhy fursat hi na milli parhny ki faraz
hum tery sheher main bikty rahy kitabon ki tarha

_________
Ab Nend Se Kaho Hum Se Sulah Kar Le Faraz,
Wo Dour Chala Gaya Hai Jis K Lie Hum Jaga Karty Thy.

______
In Barishon Se Dosti Achi Nahi FARAZ,
Kacha Makan Hai Tera Kuch Yu Khayal kar.

________
Bas Yehi Soch Ker Tujhse Mohabbat Kerta Hoon Mein Faraz,
Mera To Koi Nahi Hai Magr Tera TU Koi Ho!!

________
Ungliyan aaj bhi is soch me ghum hai faraz
Usnay kaisay naye haath ko thaama hoga

_________

BHOOLE HAIN RAFTA RAFTA UNHAIN MUDDATON MAIN HUM.
QISTON MAI KHUDKUSHI KA MAZA HUM SE POOCHIYE

Kuch muhabat ka nasha tha pehle hm ko Faraz.
Dil jo tota to nashe se muhabat ho gai. ———————————-
Yeh wafa to un dinon ki baat hay “Fraaz”
Jab makaan kachy or log sachay hoa krty thy……———————————-
Kon data ha umar bhar ka sahara aay Faraz….
LOG tu JANAZAY man bhi kandhay badaltay rahtay hein….

———————————-
“Kis ki Kya majal thi jo koi Hum ko kharid sakta”,,,
Faraz,..
“Hum to khud hi Bik gaey kharidar dekh k”…

———————————-
‘”Ham na badlein gay waqt ki raftaar kay sath,,,
‘”Faraz”‘
Ham jab b milen gay andaz purana hoga…’”.

———————————-
“Tera Na Ho Saka To Mar Jaon Ga Faraz.
Kitna Khobsurat Wo Jhoot Bolta Tha”.

———————————-
Wo Bewafa na tha youn hi badnaam ho gya,,,,
Faraz..,…
Hazaron chaheny waly thy kis kis say wafa karta……
-

———————————
Hum pe faqat ilzaam k hum hain zuban daraz…….
hum ne to bus kaha tha hamain tum se piyar hai….!
———————————-
Zindagi to apnay hi Qadmon pe chalti hai Faraz..,
Auron k $aharay to Janazay utha kartay hain..!
-
———————————
Yahee soch kar us ki har baat ko sach mana hay
“FARAZ”~
K itnay khubsoorat Lub jhoot kesay bolain gay..~
-
———————————
Bari Mushkil se Sulaaya tha Khud Ko FARAZ Main ne Aaj…!
Apni Aaankon Ko Tare Khuwaab Ka Laalach Day Ker…..!
-
———————————
Be nàam zىndagى ki haqeeqat na poochhiye ‘FARAZ’,
Kuch pur khaloٍs log thay,barbàd kr gaey…….
-
———————————
Wo roz dekhta hai dubtay huay suraj ko faraz.
Kash mai b kisi shaam ka manzir hota….!
———————————-
Main us k Haathon me tha
Tute hue Sheeshe ki trha “Faraz”,
Bari Umeed thi k bikhrne nhi dega.
Bus giraya kuch is Ada se k
Simatne ki Aaas hi na rahi.

——————————–
Bara naaz tha un ko apne parde pe faraz…
Kal raat woh khawab me sar-e-aam chale aaye…
———————————-
Kabhi Kabhi Wo Mujhe itna Yad Aata He Faraz
Me Zid Me Aa K Usay Yaad B Nahi Karta

——————————–
Mere kahny sy na paband-e-wafa ho jana,
dil na many to kse waqt juda ho jana,
na chaho jan se ziada kise ko
Faraz,
tum ny dekha nahen bandon ka khuda ho jana.
—–
—————————–
Tum is shehar k khuloos se waqif nahi FARAZ
Ye to Mohsin ko bhi sar-e-aam saza daitay hain!

Light Weight Web Servers (Light weight alternatives to apache)

November 25, 2009 at 3:28 PM | Posted in Servers | 2 Comments

Lightweight web servers are Web servers which have been designed to run with very small resource overhead because of hardware, environment, or simply for the challenge of it.
Based on my research, following are the list of few web serves, which looks nice to me, based on few parameters like performance, resource utilization, size, active development, security etc.. Also, most of them are free and open source.
Lighttpd:- www.lighttpd.net
Nignix:- www.nginx.net
Cherokee:-www.cherokee-project.com
Thttpd:- www.acme.com/software/thttpd
Mathpod www.acme.com/software/thttpd
Jetty:- www.mortbay.org/jetty
Yaws:- http://yaws.hyber.org
mini_httpd:- www.acme.com/software/mini_httpd

But the above list is very small and you can find lot of others light web servers which suits your requirement.

Out of the above list, Lighttpd and Ngnix are the two most popular free, open source light weight web servers.
Comparison between these two servers:
http://hostingfu.com/article/nginx-vs-lighttpd-for-a-small-vps
http://superjared.com/entry/benching-lighttpd-vs-nginx-static-files/
http://www.wikivs.com/wiki/Lighttpd_vs_nginx

Comparison of different light weight web servers:
http://en.wikipedia.org/wiki/Comparison_of_web_servers
http://en.wikipedia.org/wiki/Comparison_of_lightweight_web_servers

List of web servers:
http://www.debianhelp.co.uk/apachealternatives.htm
http://www.linuxlinks.com/Software/Internet/WebServers/Mini_Servers

Adding script to run at startup or shutdown in Linux

March 10, 2009 at 3:45 PM | Posted in Linux | 2 Comments

1. Write a script and put it into /etc/init.d/ directory. Your script must have start or stop options or both, depends on when you want to run your script. start is called at reboot or system startup and stop is called at shutdown.
2.  Add the executable permission to your script. Let say your script name is test
# chmod +x test

3. Create symbolic link in /etc/rc#.d where # is runlevel number. To know more about run level check /etc/initab or check init man page (type man init).
For example if you want to run your script at system startup,  create a symbolic link in /etc/rc3.d:

    # cd /etc/rc3.d/
    # ln -s ../init.d/scriptname S##scriptname where ## is order of executing script or you can say starting number. Use some 50 or 60. You should choose this number according to the needs of your application: if you try to make the application start too early, all disks may not be mounted yet, network adapters might not be initialized or some system services might not be started yet.
    the rc script will start all scripts with a capital S in numerical order.
    The shutdown portion is similar. Go to the run level that you want to shutdown at:
    - cd /etc/rc0.d/
    - ln -s ../init.d/scriptname K##scriptname where where ## is order of executing script or you can say starting number. Use some 50 or 60.
    the rc script will shutdown all scripts with a capital K in numerical order.
    sample script

    #!/bin/sh
    # Copy at startup and remove at shutdown
    #
    start() {
    cp /etc/test /var/tmp/
    }
    stop() {
    rm -rf /var/tmp/*
    }
    case “$1″ in
    start)
    start
    ;;
    stop)
    stop
    ;;

    *)
    echo $”Usage: $0 {start|stop}”
    RETVAL=1
    esac
    exit 0
    4) Your process is done. Now you can test your script.

    Few commands for runlevel and init
    1) To switch to particular run level use init
    $ telinit 6

    2) chkconfig is a tool that helps in creating/deleting/changing the symbolic links. It requires that you put two specially-formed comment lines in your application startup/shutdown script:
    #chkconfig –list to check the current startup settings
    # chkconfig: 345 80 20
    The numbers on the chkconfig line:
    - The first number (345) is a list of runlevels you’ll want your application. So it will run at runlevel 3, and 5.
    - 80 is the “starting position” number, meaning that this application will be started rather late in the boot process.
    - 20 is the “shutdown order” number. Unless your application has special requirements, it is recommended that the sum of startup and shutdown order numbers for each application should be 100.

    When you have added the two “magic” comment lines to your startup/shutdown script, just place the script to /etc/init.d and run:
    chkconfig –add
    If you need to temporarily block the system from starting/stopping the application automatically, you can use:
    chkconfig off
    To restore the auto-start function, use:
    chkconfig on

Install packages on Linux…

March 10, 2009 at 12:12 PM | Posted in Linux | Leave a comment

Make and install program from source (tar.gz)

  1. Put the packed file (tar.gz)  in the directory you want it to be installed under.
  2. Open the compressed tar ball   “tar zxvf <packagename>.tar.gz” .  It will create a directory like “packagename-2.3.4″ and place the extracted information here.
  3. Go into the created subdirectory and type “./configure”.
  4. Type “make all”
  5. Type “make install”

RPM (Red Hat Package Manger)  – Most common method of distribution of software for Linux. rpm command provides for installation, removal, upgrade, verification and other management of RPM packages.

1) Install new package – use rpm -i or rpm ihv for verbose information
#rpm -ihv gcc-2.96-113.i386.rpm

2) To upgrade a existing package to newer version -
#rpm -U binutils-2.11.93.0.2-11.i386.rpm

3) To remove a package
#rpm -e binutils-2.11.93.0.2-11.i386.rpm

Frequently used option in uninstall
–nodeps – skips dependency checking
–test – Run through all the motion except for actually installing things. Useful to verify that a package can be uninstalled correctly.

4) Query about package (-q)
-a display a list of all the packages installed on the system  –   rpm -qa
-f filename – display a package that contain file name
-R list packages on which this package depends

To know about any installed package
#rpm -ql <package_name> or rpm -qa|grep <package_name>
To list the files contained in the package
#rpm -qlp binutil.i386.rpm

Setting Environment variable in Linux

March 5, 2009 at 11:10 AM | Posted in Linux | 2 Comments

The following setting is for FC8 Linux. The file name or path may change for different flavor of Linux
For system wide effect , edit /etc/bashrc file and for particular user edit file home/<username>/.bash_profile and add your environment variable. For example, adding JAVA_HOME variable
#export JAVA_HOME=/usr/bin
Then save the file and run it using source command.
#source /etc/bashrc or source /home//.bash_profile
You can test it by
echo $<your_variable_name>

Install Internet Explorer 6 on Linux

February 18, 2009 at 6:19 PM | Posted in Linux | Leave a comment

Open a terminal. Log in as root to install wine and cabextract:

yum -y install wine*
yum -y install cabextract

Logout and install IEs 4 Linux with your normal user account:

wget http://www.tatanka.com.br/ies4linux/downloads/ies4linux-latest.tar.gz
tar zxvf ies4linux-latest.tar.gz
cd ies4linux-*
./ies4linux

GNU screen tutorial

February 12, 2009 at 2:35 AM | Posted in Linux | 1 Comment

Screen is best described as a terminal multiplexer utility. It allows you to have multiple virtual terminal instances over a single terminal connection.
Creating a new session
To start screen type screen on command prompt.
$ screen
or you can give screen name also
$screen -S <screen name>
Creating a new window
Type Ctrl+a c.
Every new created screen window is identified by an unique number. The first window (the one you’re actually using) is numbered as 0, while future windows will be labeled as 1, 2, 3 etc.
Switching between windows
a) Use Ctrl-a n and Ctrl-a p to switch to the next or previous window in the list and Ctrl-a space, to toggle through the shells.
b) Use Ctrl-a N, where N is a number from 0 to 9, to switch to the corresponding window.
c) Use Ctrl-a ” to get a full-screen list of windows. You can navigate this list with the arrow keys (or vi-style, with j and k), and pick a window to activate by pressing Enter when it’s highlighted. C-a w will give you a small, non-interactive list of windows.
Renaming Windows
Type Ctrl-a A, it will be prompted for a new window name.
Detaching and reattaching
Type Ctrl-a d for detach
$screen -r to re-attach or resume session

Sharing the session between multiple user
We’ll use a very simple scenario for this one. Let’s say Jake wants to share access to a screen session with Bob. Jake & Bob both have accounts on the system.

1. In order to enable multiuser mode the screen binary must be setuid for root.
# chmod u+s /usr/bin/screen
2. Jake starts a screen session.
jake$ screen -S shared
3. Jake must enable multiuser mode.
CTRL+a : multiuser on
This could be added to ~/.screenrc to have it enabled for all sessions, but case-by-case is probably safer.
4. Jake must add Bob to the access control list for his session.
CTRL+a : acladd bob
5. Bob lists the screen sessions that Jake has available.
bob$ screen -list jake/
There are several screens on:
1951.pts-1.testbox (Private)
1994.shared (Multi, attached)
2 Sockets in /tmp/screens/S-jake.

This shows us that Jake has 2 sessions. The second session named “shared” is a multiuser session & Jake already has it attached.
6. Bob attaches Jake’s multiuser session.
bob$ screen -x jake/shared
Bob could also connect using the PID.
7. Jake can check to see if Bob is connected to his session.
CTRL+a *
This brings up a list of users in a screen session.
term-type size user interface window
———- ——- ———- —————– ———-
xterm 80×24 bob@/dev/pts/11 0(email) rwx
linux 80×24 jake@/dev/tty1 0(email) rwx
[Press Space to refresh; Return to end.]
8. Jake can boot Bob from his screen session.
CTRL+a : acldel bob
Bob is immediately disconnected and sees…
[remote detached]
bob$

Monitoring
Say you’ve got a whole bunch of windows open. One of those windows is idling in a very inactive IRC channel. Since not much goes on in there, you don’t keep that window active but you would like to know when something is said. screen lets you monitor any window for activity by first switching to the window, and then hitting ^A M. When activity in that window occurs, screen will display a message at the bottom.
On the other hand, say one of your windows is a compile of X. There’s lots and lots of activity and you’d like to know when the build is finished. You can monitor for 30 seconds of inactivity by switching to the window and hitting ^A _. When the window goes silent, screen will display a message at the bottom.
These monitoring commands are toggles, so you can turn them off by switching to any monitored window and issuing the command again.

Copy and Paste
Here’s a feature that can be useful if you’re stuck in console mode & don’t have a mouse available. screen has its own built in buffer for copying & pasting text into the same or other windows.
1. Enter copy mode by pressing CTRL+a [
The status bar will read "Copy mode" with column & line information.
2. Move the cursor to the beginning of the block you wish to copy using standard vi keys or the arrow keys.
3.Press the ENTER key.
The status bar will read "First mark set" with column & line information.
4. Move the cursor to the end of the block you wish to copy using standard vi keys or the arrow keys.
5. Press the ENTER key.
The status bar will read "Copied X characters into buffer".
6. Paste the copied text with CTRL+a ]

Next Page »

Blog at WordPress.com. | Theme: Pool by Borja Fernandez.
Entries and comments feeds.

Follow

Get every new post delivered to your Inbox.