luni, 24 septembrie 2012

Unusual commands in linux : pv

Today I will speak about pv command.

Pipe viewer - pv is a terminal-based tool for monitoring the progress of data through a pipeline written by Andrew Wood

To install pv on Fedora or CentOS do this:

$ sudo yum install pv

You can read the man file to get more help:

man pv

The result is:

       pv - monitor the progress of data through a pipe

       pv [OPTION] [FILE]...
       pv [-h|-V]

       pv  allows  a  user  to see the progress of data through a pipeline, by
       giving information such as time  elapsed,  percentage  completed  (with
       progress  bar),  current  throughput  rate, total data transferred, and

       To use it, insert it in a pipeline  between  two  processes,  with  the
       appropriate  options.  Its standard input will be passed through to its
       standard output and progress will be shown on standard error.

Let's see some examples.

You can get precisely time how long it will take.

$ pv | python 
 737B 0:00:00 [86.9kB/s] [==================================>] 100%

You can see how fast the computer reads from /dev/zero.

$ pv /dev/zero > /dev/null
1.1GB 0:00:05 [   2GB/s] [    <=>                                            ]

You can use the dialog to show progressbar.

To do this you need to use -n arg.

$ (pv -n /dev/zero > /dev/null) 2>&1 | dialog --gauge "Please wait" 10 70 0

miercuri, 19 septembrie 2012

Make one simple kernel module using C programming language.

Today I will try to explain how to make a kernel module.

Basically, a kernel module it's one pieces of code that can be loaded and unloaded into the kernel.

You can read about kernel modules from here.

Now, let's try to make a simple kernel module.

Writing your own module can be done if you know some basic rules.

First, about how to use modules.

Suppose you have a new module named kernelmoduletest.

How to load the module.

Just use this command in your module kernel folder:

#insmod kernelmoduletest.ko

Next, test the kernel module messages.

This can be done with:

#dmesg | tail

Also , you need to remove the kernel module.

$ rmmod kernelmoduletest 
ERROR: Removing 'kernelmoduletest': Operation not permitted

This mean you need to have superuser rights.So use the sudo or su command.

Then use the rmmod command.

Know how to make the kernel module skeleton.

This is not very simple because you need to know many things about kernel and programming.

But you can try test with some simple example like this example:

Create the c file named kernelmoduletest and add this source code:

#include <linux/module.h>
#include <linux/kernel.h>

MODULE_AUTHOR("Catalin George Festila/mythcat/catafest");

int init_module() {

    printk(KERN_INFO "Now I will initialize my  kernel module\n");

    printk(KERN_INFO "Test: Hello World !\n");

    return 0;

void cleanup_module() {

    printk(KERN_INFO "Bad!... kernel module unloaded.\n");

Make a new file named Makefile.

Add this to tell how to compile the kernel module.

obj-m += kernelmoduletest.o
 make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
 make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean

Compile your kernel module

Just use make command.

# make
  Building modules, stage 2.
  MODPOST 1 modules
make[1]: Leaving directory `/usr/src/linux-headers-2.6.31-14-generic'

If you test your module using the commands from the top of this tutorial, you can see that:

[14694.779227] Now I will initialize my  kernel module
[14694.779233] Test: Hello World !
[15049.825605] Bad!... kernel module unloaded.

If you have already made kernel modules and the subject it's interested for you, send me an email.

Thank you. Regards.

Something about blogspot feeds and adsense settings.

Today I did something for my blogs.

I did email settings rss and you can watch them more easily.

The main reason I blog is that it treats many different topics.

I met something weird. Rss for content adsense settings requires Full option.

If you want to make settings for content only and not for comment when you have to choose the Custom option. See next note from help.

Post Feed Footer
Close help
This will appear after each post in your post feed. If you use ads 
or other third-party feed additions, you can enter that code here. 
You must also set Allow Blog Feeds to Full (above).

To set jut Blog Posts Feed using feeds than you need do this:

Allow Blog Feed ?  

Blog Posts Feed

Blog Comment Feed

Per-Post Comment Feeds

How exactly it's reflect this with adsense scripts...

Note:... my blogs :

pygame blog
python blog
graphics and more
this blog - about my life

duminică, 2 septembrie 2012

Tips and tricks: watch and cat

Sometimes it is necessary to find solutions.

Today's example involves two linux commands:

watch and cat

Here is a simple method by creating a script that returns an output:

while [ 1 ]; do cat /proc/meminfo; date; echo; sleep 1; done

Make this script executable and name it: meminfo

Output is then processed by the command:

$ watch -d ./meminfo 

This simple method can be applied to other files ...