Search

Flash not working in iceweasel

If the some update of iceweasel has broken the flash in iceweasel,and all flash sites stop working , we might see the following message in the page Tool->Addons->plugins



The link given in the page to update the flash might be broken.

The workaround for this is to update the flash with the latest one from



Select the .tar.gz version for debian systems. Close all instances of iceweasel and Untar the downloaded package.



After the untar, we will get a folder named usr, a file libflashplayer.so and a file readme.txt.

We need to copy the file libflashplayer.so to the folder which contains the plugins for iceweasel.



For mozilla copy it to .



Now launch iceweasel and the problem with flash should not occur.

cc1: all warnings being treated as errors

While compiling big source codes, written in C, most often using make, we can pass many options called as flags, to gcc compiler, to control the behaviour of the compiler while compilation.

Encountering warnings in any code is common, but some times while running the make command we might hit the error.



This is because the compiler has been instructed not to ignore the warnings and treat all the warnings as errors. This is done by passing the options -Werror to gcc compiler. Ignoring warnings in bigger codes is not considered a good practice and to avoid the same the -Werror option is used.

For example the make file could have a like passing the options as below.



We can see that the last option is -Werror. This flag causes the error that we saw above. So if we do not want to treat warnings as errors, we just need to remove -Werror from the list of Target Flags. But be careful, it might not be the wisest thing to do.

bzr: ERROR: Not a branch:

If you are trying to create a u are in the local branch of bazaar or for that matter any software code, we might get teh following error we try to pull the latest revision



For a newbie one of the common reason for this error could be simple fact that we are in the wrong folder.

Just change the folder to the folder in which the source of the code is stored in. For example if we ran the command



Then the source will be in the folder test, so before running the pull command first change the folder to test and then run pull command.




xzgrep for searching in compressed files

grep is a very powerful tool for everyone who works with text and strings. For searching through logs, errors and other text based data. But if the same data is present inside a compressed archive, like .bz2 or a .xz. Then we need to uncompress it and then use grep on the files.

If the number of such compressed files are too many, uncompressing all of them with out knowing which one contains the data that we are looking for could be a waste of time. This is were xzgrep can come to rescue.

xzgrep can search through compressed files of the formar .bz2,.xz etc and look for strings in the files like grep does. The only difference is that xzgrep can only confirm whether the search string is present in the compressed file or not and not be able to list further details like grep does.

For example let us take two files

hello1



hello2



Let us create a tar file



Compress it using bunzip



This will create the compressed file hello.tar.bz2

Now to search for text inside this compressed file.



The string 12 is present is hello1 thus the ouput says that a match is found.



If match is not found, xzgrep does not mention any thing.

But note that the xzgrep works only on the text files inside the compressed file, like grep works only on text files. Thus if the search string is inside a pdf or any other document, xzgrep will not be able to pick it up.


iceweasel fails to launch after kernel upgrade

If after upgrading to kernel version 16 or above ,iceweasel fails to launch, try launching it from the command line using the command



If you see the following error in the terminal



It means that the iceweasel needs to be upgraded. We can do that easily from the package manager. Just open the package manager search for the package iceweasel. Right click on the package and selcet "mark for upgrade" and then click on apply.

Once iceweasel is upgraded the above error should not come.


Can not create /sys/kernel/uevent_helper Permission denied

While compiling 3.16 kernels, we might hit the error

Can not create /sys/kernel/uevent_helper Permission denied.

The reason for this could be that the the config option



is not set.

Open the .config file, search for CONFIG_UEVENT_HELPER and set it to "y".



Save the .config file and recompile the kernel and boot it. The above error should not occur.


Cannot execute init (error 8)

If we hit the error





while booting a freshely compiled kernel, then the possible reason could be that we have forgotten to enable the confiog option



Open the .config file, search for the above option and if it is set to "n" or is not set then change it to



Save the file, and recompile the kernel. The above error should not appear now.

Using enchant to spell check on the command line

Spell check is a common operation on all text files. All the editors come with built in spell checkers. But if we want to run a spell check on a text document with out opening it we can use enchant.

enchant is a command to check spelling, and also suggest the possible correct spellings. To only list the misspelt words we can use the option -l with the command

Let us say we have a file with the following text in a file called temp



To run a spell check on the file we can use enchant.



We can see that we have list of words that have been misspelled.

To get the line numbers in which the misspelled words are present we can use the option -L.



The first column is the line numbers and the second column the line numbers.

To get suggestions on possible corrections we can use the option -a.



Every line that starts with a & is the output for a misspelled word. The misspelled word is followed by all the possible suggestions.

error: ‘SPIN_LOCK_UNLOCKED’ undeclared here (not in a function)

While writing a kernel module using the spin locks in linux, we might hit the error



This might happen if we are trying to compile the module for kernel version below 3.0 Because before kernel version 3.0 SPIN_LOCK_UNLOCKED was defined in spinlock.h



But this definition is no longer available, and is replaced by DEFINE_SPINLOCK in spinlock_types.h



Thus in the module remove the initialization with SPIN_LOCK_UNLOCKED and add the macro DEFINE_SPINLOCK to get around the error.

Using the watch command to run a script or command periodically

At times we need to run certain commands repeatedly and watch the output. It could be as simple as looking into the log files, to running some scripts.

For such repeated running of commands we can use the command watch.

Watch is a command that runs a command periodically at fixed intervals untill not stopped.

For example



The command "echo hello" will be run every two seconds and the output displayed on the terminal. The previous output will be replaced by the new output, thus in this case we will not see any change in the output.To quit we can use the keys "Ctrl + C".

To be able to see clearly the repeation of the command let us create a file called temp,using gedit, and enter the text "Hello" in it. Save the file and in the terminal go to the folder where the file is stored. Now execute the command



Now go back to the file and add the text "world" to it and save it. Go back to the teminal and see the change in the output.



We can see the updated text appear in the output.

By default the watch executes the command every 2 seconds, but that can be changed using the option "-n"



To be able to see the differences between consecutive outputs, we can make watch to highlight the differences in the output using the option -d

This option -d is very useful when we want to contiously look at logs and find out differences between two consecutive logs.

If we do not want to see the heading line which indicates the repetion interval, the command and the current time we can use the option -t.

Creating GUI of menu list in linux scripts

In the post we saw how to install whiptail and use it to create GUI in a linux terminal. Taking it a step further, let us see how to create menu like list like GUI in a linux terminal.

The option to be used for creating a menu is --menu, the syntax being



The value and description pair being the main part of the menu list. The value is the value that is assigned to the menu item and what follows is its description.

Example





 photo whip_menu_1.png

In the above Example A is the value Menu1 its description, B is the value and Menu2 its description. We can any number of such menu value pairs.

We can move between these menu value pairs using the arrow keys and which ever menu we select and press enter, that value of that menu item is sent to the standard error.

In the above example, if we press enter by selecting "B Menu2", value B is sent to the standard error.

To be able to store this value for futher use in a script we need to redirect the standard error to value, which can be done by swapping the file descriptors of standard output and standard error.



Which ever option is chosen the value of the same gets stored in the variable option.

Here is an example script which makes use of the menu list to get data from the user.



Give the script execute permission and run it to see the output



 photo whip_menu_2.png

 photo whip_menu_3.png


Taking password using GUI in linux script using whiptail

In the post we saw how to install and use whiptail. We can use whiptail to accept passwords from user too.

The syntax to use the password is



Example



The password entered will not be visible and will appear only as *. But by default the entered password is sent to the error console.

 photo whip_pass.png

To use the password in the script, we will have to swap the standard error and standard output consoles which can be done as below.



what ever password the user enters, it will be stored in the variable input.

Here is an example script, in which we will take the user password and verify if the same is correct or not.



Save the script, give it execute permission and run it. $ chmod 777 whiptail_password.sh $ ./whiptail_password.sh

 photo whip_pass.png

 photo whip_correct_pass.png


Taking input from user using whiptail

In the post "Creating message box in a shell script" we saw how to install whiptail and use it to create a basic message box in scrpting.

Other than just displaying messages, scripts also take input from user. Whiptail can be used to create a small GUI for the user to enter his or her input.

To create an input box we need to use the option --inputbox, the syntax being



Example



 photo whip_input.png

By default whiptail passes the input entered to the standard error console, and in a usual shell we will be able see the entered text on the terminal after we exit from the whiptail window.

But if we want to use the entered input by storing it in some variable, we will have to go about a few manipulations as there is no direct way of doing it in whiptail.

The simple manipulation we will have to do is swap the standard error console and the standard output console which can be done by appending



to the command.

Thus we can write the whiptail command as



The varialbe val will get the value that is entered in the inputbox.

Here is an example script to see the use if inputbox

whip_input.sh



Give the script execute permission and run it to see the output



 photo whip_input_tux.png

 photo whip_hello_tux.png


Creating yes no option box in linux scripting

In the post "Creating message box in a shell script" we saw how to create a message box using whiptail. Now let us see how to create a yes/no box where the user can choose one of the two and then the further action can be decided.

The syntax to create a yesno box using whiptail is



Example



 photo whiptail_yesno.png

If we select yes, the return value of the command will be 0, for no the return value will be 1. We can use the return value to decide the further course of action for the script.

Here is a script that keeps popping up the yes/no box as long as the user does not select "no" to stop the script.



$bash yesno.sh  photo whip_continue.png

 photo whip_yesno.png


Creating message box in a shell script

Shell scripts are generally assumed to be restricted to using only the command line for interaction with the user and lacks the graphical user interfaces available in the GUI mode.

One way of creating small GUIs in shell scripts is by the use of whiptail.

Here is how we can create a message box using whiptail. To create a message box we need to use the option --msgbox.

syntax:



example



The above command will create a message box of 10 X 20 with the text hello in it as shown below.

 photo whip_tail_msgbox.png

By default the text that appears for exiting the message box is OK.

We can changet the text using the option --ok-button



 photo whiptail_ok_button.png



Example script




Carving text on image using gimp

We often want our images to have some text carved on it. Here is how we can do it easily using gimp.

Launch gimp and click on File->Create->Logos->Carved

 photo gimp_carved_select.png

The following menu will appear.

 photo gimp_carved_text.png

In the text field enter the text that has to be carved on the image.

Font Size: The size of the font to be engraved. Select this carefully depending on the size of the image.
Font: The fonr to be used for the characters of the text.
Background Image: Browse and select the image on which the text need to be carved.
Carve raised text: We can tick this check box when we want the text to stand out in a raised manner from the image.
Padding around text: How much spacing should be between the image borders and the text.
For our example we will write the word Linux on the image of the "tux", the linux penguin.
After setting all the above fields click on ok.

The gimp screen will come up with the carved text. The default color of the text is almost white as shown below.

The color can be changed by using the bucket tool available in the toolbox and filling the characters with our desired color by selecting the top most layer among all the layers.

 photo gimp_carved_linux.png

After coloring we will have to export the image using File->Export and choose the path and name for the final file. The following is the final result after coloring the text red.

 photo linux_mbed_2.png

Note that the image being small, it has been repeated to accommodate the whole text.

Creating a queue in linux kernel using list functions

In the post we saw how to create a stack using the list functions. In this post let us use the same list functions to implement a queue.

As we know a queue is a data structure that stores data in the first in first out order. That is the data that is entered first is read out first.

To create a queue using the list functions we can make use of the function list_add_tail



new: The new node to be added
head: Pointer to node before which the new node has to be added.

To make the list work as a queue we need keep inserting every new node before the head node, that is at the tail end of the list and when we read the list, we read from the front end. Thus the entry that is added first will be accessed first.

To demonstrate the operation of queue we will create a proc entry called as queue make it work like a queue.

To create the queue we will use the structure



queue_list : Used to create the linked list using the list functions.
data: Will hold the data to be stored.

In the init function we need to first create the proc entry and then intialize the linked list that we will be using for the queue.



create_new_proc_entry: Function for creation of the proc entry.





Next we need to define the file operations for the proc entry. To manipulate the queue we need two operations push and pop.



The function push_queue will be called when data is written into the queue and pop_queue will be called when data is read from the queue.

In push_queue we will use the function list_add_tail to add every new node behind the head.



In the function pop_queue, before attempting to read the queue, we need to ensure that the queue has data. This can be done using the function list_empty.



Which returns true if the list is empty.

In case the list is not empty, we need to pop out the first data from the list which can be done using the function list_first_entry.



ptr: Pointer to the head node of the list.
type: type of structure of which the head is member of
member: The name of the head node in the structre.
Thus the pop function will look as below.

The flag and the new_node are variables used to ensure that only one node is returned on every read of hte proc entry. The read function from user space will continue to read the proc entry as long as the return value is not zero. In the first pass,new_node=0, we will return the number of bytes of data transfered from one node and in the second pass,new_node=0, we will return 0 to terminate the read. Thus making sure that on every read data of exactly one node is returned. The flag variable works in the similar fashion when the queue is empty to return the string "Queue empty".

Thus the full code of queue will be



To compile the module use the make file.



Compile and insert the module into the kernel



To see the output

Thus we have written the 1,2,3,4 as data into 4 nodes with 4 being inserted last. Now to pop data out of the stack

Implementing stack using the list functions in kernel -2

In the post "Implementing stack using the list fuctions in kernel" we saw how to create a stack entry using the in built list functions of the kernel. Some of the operations that we did while creating the stack can further be automated using some more list functions of the kernel.

We had used a variable "tail" to keep track of the last element of the stack, which was being updated in the push_stack function after every write to the stack. This is not really needed is we use the function list_last_entry.



ptr: Pointer to the head node of the list. type: type of structure of which the head is member of member: The name of the head node in the structure.

For our example, we can use list_last_entry as below.

list_last_entry automatically returns the last node of the list and there is no need to keep track of the tail node.

Thus the push function can be modified as below.



In the pop_stack function, the check for stack being empty was being performed by comparing the tail with the head pointer. This can be easily by using the function list_empty, which returns true is the list is empty



head: Pointer to the head node of the list which is being tested.

list_last_entry can also be used in the pop_stack function to read out the last element of the stack.

Thus the modified pop_stack will look as below.



The complete modified code for stack being

stack_list.c



To compile the module use the make file.



Compile and insert the module into the kernel



To see the output



Thus we have written the 1,2,3,4 as data into 4 nodes with 4 being inserted last. Now to pop data out of the stack



Thus we can see that the proc entry is operating as a stack.
Related posts

Implementing stack using the list functions in kernel
Creating a read write proc entry in kernel versions above 3.10
Pointer to structure from its member pointer: container_of

Finding trignometric inverse in gcalctool in linux

Most linux distros come with gcalctool as the default calculator. It is not obvious on first look as how to find the inverse of trignometric terms in gcalctool. Here is how we can do it.

This is the default look of the gcalctool.

 photo gcalc.png

Let us say we want to find arcsin(0.9)

Type sin or press the sin button

 photo gcalc_sin.png

Now press the up arrow, which is the second button from left in the first row and then type -1.

 photo gcalc_inv.png

Now press the up arrow again to come out of superscript mode.

Now enter the value 0.9 and press enter.

 photo gcalc_sin_inv.png

And we have the angle in degrees for arcsin(0.9)

 photo gcalc_angle.png

Implementing stack using the list functions in kernel

In the posts "Creating a linked list in linux kernel" and "Using list_del to delete a node" saw how to use the in built functions of a kernel to build a linked list. One of the main applications of linked list could be the implementation of stack. In this post, let us make use of the list functions available in the kernel to implement a stack.

A stack, as we know, is a data structure that stores elements in the order of first in last out. So when ever we write or push data into the stack, the data needs to be added as a node at the end of the list and when we read data from the stack we need to read data from the last node of the list and then delete the corresponding node. To implement a stack using a list, we need to keep track of the last element that gets inserted into the list, because when ever we need to read from the stack we need to return the data stored in the last node.

To implement the stack operation using list functions, we will make use of the function



Where
new: The new node to be added to the list
head: Is the node after which the new node has to be added.
If we have to implement a linked list from scratch we would have had to take care of all the pointer manipulations when inserting data into the list or removing data from the list. But as we have the required help, as built in functions, all we need to do is call the right function with the right arguments.

To show the operation of a stack we will make use of a proc entry. We will create proc entry named as "stack" and make it behave as a stack. We will use the following structure as the node



test_list: Will be used to create the linked list using the built in functions of kernel
data: To hold the data of the list.

The first thing we will have to do, to implement a stack using proc entry is create a linked list and create a proc entry in the init function.



create_new_proc_entry : Function to create a new proc entry.



INIT_LIST_HEAD: Initialize the linked list with the head node as test_head.

tail=&test_head; : With no data in the stack the tail and the head point to the same node.

emp_len=strlen(empty): "empty" is the message to the printed when the stack is empty and strlen returns the length of the string.

Once the initialization is done we need to associate the functions for push, writing data to stack and pop, reading data from stack.



Now we need to implement the functions pop_stack and push and stack.

push_stack:



msg=kmalloc(10*sizeof(char),GFP_KERNEL): allocate memory for the data to be received from the user space.
temp=copy_from_user(msg,buf,count): copy the data from user space into the memory allocated
node=kmalloc(sizeof(struct k_list *),GFP_KERNEL): Allocate a new node.
node->data=msg: Assign the data received to the node.
list_add(&node->test_list,tail): Add the new node to the list. Note that we are passing the node after which the new node has to be added as tail. This makes sure that the list behaves as a stack.
cnt++: Increase the count of nodes that are present in the list.
tail=&(node->test_list): Change the node to point to the new node of the list. Note that we are assigning the address of test_list to tail and not the address of the node.

pop_stack:



In the pop operation we pop the last element inserted into the stack and then delete the node. According to the push_stack function, the variable tail points to the last element inserted into the stack.

According the standard practice followed in the the kernel, the read operation has to return the number of bytes of data transfered to the user space and user space functions continue to read as long as they do not get a 0 as return value indicating end of the read operation.

To make the proc entry work as a stack, we need to make sure that every read operation return only one node. To ensure this, in the above code we have used a variables new_node and flag, which after returning the data of one node or empty stack, respectively, makes the return value to 0, which ensures the read is terminated.

While popping data out of stack, we need to first check if the stack has data in it. This is done by comparing tail with test_head. If test is pointing to test_head it means the stack is empty and we return the string "Stack Empty". This is implemented by following piece of code



On the other hand if stack has data in it.



node=container_of(tail,struct k_list ,test_list): Get the pointer to the node which has the tail, last node of the list, as its member.
msg=node->data : Assign the data in the node to msg
ret=strlen(msg): Get the length of data to be transfered.
new_node=0: set new_node to 0, to indicate one node has been read.

Set count value to sting length, if count is larger than string length and reduce the variable ret by count value.
ret become 0 when ever the count valur is greater than ret.
temp=copy_to_user(buf,msg, count): Copy msg to user space.


Once all the data from the node has been transferred count becomes 0, not we need to change the tail to point to the node previous to the current node.

tail=((node->test_list).prev): Assign to tail the address of test_list of previous node.
list_del(&node->test_list): delete the node from the list.
new_node=1: Set new_node to 1 for the read of next node.

The full code for the kernel module looks as below.

stack_list.c



To compile the module use the make file.



Compile and insert the module into the kernel



To see the output



Thus we have written the 1,2,3,4 as data into 4 nodes with 4 being inserted last. Now to pop data out of the stack



Thus we can see that the proc entry is operating as a stack.

Related posts

Implementing stack using the list functions in kernel-2
Creating a read write proc entry in kernel versions above 3.10
Pointer to structure from its member pointer: container_of

Creating checkerboard image using gimp

Here is how we can create a checker board background or an image of checker board using gimp. Launch gimp and create a new image by selecting file->new.

 photo gimp_new.png

Select the size of the image that is reqiured. In this post we will use the sizw 640X480.

 photo gimp_new_temp.png

Once the new blank image is created, select the menu Tools->GEGL operation

 photo gimp_tools_gegl.png

In the pull down menu for operations select the option checkerborard.

 photo gimp_gegl_options.png

The follwing menu should appear.

 photo gimp_cheker_options.png

Width: Width of the boxes

Height: Height of the boxes

X offset:Defines from where does the boxes start from at the left margin

Y offset: Defines from whese does the boxes start from at the bottom.

Color,Other color: These can be used to set the colors for the boxes

Click on OK to create a checkerboard image, which we can export as an image or use it as a background for other layers.

 photo gimp_checker.png

Final image:

 photo checker.jpg


Using list_del to remove a node from a linked list

In the post " " we saw how to create as linked list using the built in functions of linux. Now let us see how we can delte the nodes of the linked list.

The deltetion of nodes in a linked list has to be done carefully to make sure that even after the deletion of a node the list retains its structure. That is no matter from which position the node is deleted, the head, the tail or in between, the link between the remaining nodes should be retained.

If we delete the node at the head, then the node to which it was pointing to becomes the new head. If we delete the node from the tail, then the node to before it becomes the tail and if we delete the node from in between, the node previous to the delted node should be made to point to the node to which the deleted node was pointing to, making sure that the link between the nodes are maintained.

The kernel developers have made the above process very easy for us by providing the function



entry is the pointer to the node which we want to delete.

We need not be bothered whether it is the head,tail or in between the kernel takes function takes care of it.

Let us take the code that we used to create the list in the post "Creating a linked list"

In the init part of the module we have create three nodes in the linked list. Now let us add the deletion of nodes to the same init function, and print the linked list after every deletion.

For example to delete the "one" we need to call the function



and after every deletion we will iterate over the list using list_for_each

delete_list.c



To compile the module use the make file.



Compile and insert the module into the kernel



To see the output use the command demsg



In the above output the first three lines are creation of the linked list. Then after deleting each node we iterated through the list and see the that each call to list_de deletes one node from the linked list.

Teminating a kernel thread using kthread_stop

In the post "Kernel thread creation 1 " we saw how to create a kthread in linux using kthread_create. The function we used to stop the thread was kthread_stop.

But kthread_stop does not terminate the thread by itself, it waits for the thread to call do_exit or terminate itself. kthread_stop only makes sure that if the thread calls the function kthread_should_stop, then kthread_should_stop returns true.

So just by calling kthread_stop in the cleanup function we can not trerminte a thread in between unless the thread does not exit by itself. To be able to terminate a thread in between, i.e. as soon as kthread_stop is called, we need to make sure that thread keeps checking for the function kthread_should_stop.

If kthread_should_stop returns true, which happens when kthread_stop is called on the thread, then the thread should exit by calling the do_exit.

Taking the same example as in the post "Kernel thread creation 1" , we need to add the following lines of code to the thread function



Thus the thread function would look like



Thus the full code for a creating a kernel thread which will terminate on call to kthread_stop would be

kthread_terminate.c



The makefile for the module would be



compile the module and insert it



To see if the therad has been created we can use the command ps



Now if we remove the module, the thread should get terminated immediately and module removal should not wait for the thread to complete as was the case in the module where kthread_should_stop was not used in the thread function.



Related links: Kernel thread creation 1 Kernel thread creation 2 Kernel thread creation 3

Configure and connect tata photon plus in debian 7

The 3G dongle of tata photon+ (Huwaei EC1260) might not work by default in debian 7, and other linux distros. Here is how to get it working.

The first step is to install the packages, if not already installed.





Once the two packages have been installed successfully, next we need to install wvdial



After installing the pakcage, insert the dongle.

Now open a terminal and type the command



We will see an output as below



The fourth line from below recognizes our dongle as the device /dev/ttyUSB0

Next we need to configure the wvdial application to allow it use the dongle to connect to the internet.

For doing this we need to open the wvdial.conf file located in /etc/wvdial.conf



By default the file will look some thing like below



Delete the ";" at the beginning of the lines "Phone","Username", and "Password". and replace the three lines with



Then add the following lines to the file at the end.



The edited wvdial.conf looks as below.



Save the file and close it. Now go back to the terminal and type the command



Now open a browser and start browsing.

Note that before running the command wvdial in the last step, turn off mobile broadband in the gui mode.

error: function declaration isn’t a prototype [-Werror=strict-prototypes]

While compiling kernel modules, or any c program, we might at times come across the error



This error is being shown for the function declaration



Though the syntax looks fine, the compiler is expecting us to pass "void" in case we are not passing any arguments to the function. That is we need to modify the above function to

After the above change, we should not get the above error.

Creating jigsaw of image using gimp

Using GIMP any photo can be made to look like a jigsaw puzzle easily. Let us take the following image for an example.

Launch gimp and click on

File->open

 photo gimp_open-1.png

Browse to location where the image is stored and open it in gimp.

 photo gimp_jigsaw.png

Now click on

Filters->Render->Patterns->Jigsaw.

 photo gimp_render_jigsaw.png

The following window will appear.

 photo gimp_jigsaw_options.png

The number of tiles option lets us choose the number of horizontal and vertical divisions that are needed for the image, higher these numbers more the number of jigsaw pieces will appear on the image.

Bevel width allows us to choose the degree of slope of each pieces's edge

Highlight lets us choose how strongly should the pieces appear in the image.

Style of the jigsaw pieces can be set to either square or curved.

Click on OK after setting the required options.

The image should appear as below depending on what values were set in the options.

 photo gimp_tux_jigsaw.jpg


Seperating pdf into single pages using pdfseperate in linux

pdfseperate: A tool than can be used to split a pdf document into individual pages or can be used to extract a set of pages as individual pages from a pdf document.

Let us say we have a document named hello.pdf, that has 100 pages and we need to extract the pages 20 to 22 as individual pages. We can use pdfseperate to achieve this.



After the execution of the command, we should have three files foo1.pdf,foo2.pdf and foo3.pdf which will be the 20th,21st and 22nd page of the hello.pdf document.

If pdfseperate is not available, we need to install the package poppler-utils, for debian based systems



iceweasel error : Error: Platform version '24.3.0' is not compatible with

On update of iceweasel in debian we might get the error



leading to failure of launch of iceweasel.

The simple solution is to reinstall iceweasel.

Open the synaptic package manager, search for iceweasel.

Right click and select Mark for reinstalation.

Click on apply

Once the installation is done we should be able to launch iceweasel .

tempfile to create temporary files in llinux

While running certain scripts we might need to create temporary files. To ease the creation of temporary files we can make use of the command



it creates an empty file with the name or with the required sufix and prefix. The default permissions for the file are 0600 that is read, write permission only for the creator.

Examples



The -n option is used to pass the name of the temporary file. The "-d ." indicates that the temporary file needs to be created in the current folder itself. We can pass a path to any folder in which we want the temporary folder.

Instead of a name of a file we can pass a suffix to the filename using -s



We can add a prefix using the option -p



Thus we can see that the the new file has been created with a suffix temp. But the user name is randomly chosen by the system. We can not choose the name of the file with -n option if we want to specify the suffix or prefix. If -n is passed the -s and -p, for prefix, are ignored.


Script to create matrix like background on the linux terminal

Here is a script which when executed on the Linux terminal will create a continuous stream of 1's and 0's to create a background like that of the matrix as shown below.

 photo matrix.png

Here is the script.




Save the script as matrix.sh

Give it execute permission and then execute it as follows



Pleast note that the script will not stop untill you do not press "cntrl + c" or "cntrl + z" or close the terminal.

dpkg: error processing oracle-java7-installer

When updating packages using synaptic package manager, in debian based systems like ubutnu etc, we might hit the following error.



The work around for the error is to remove the orackl3-java7-installer. So open the synaptic package manager, and search for



Right click and click on



Now click on the apply button and let synaptic remove the package.

This should take care of the above mentioned error.


Creating linked list in liinux Kernel using the list

Linked lists are a very frequently used data structure in the linux kernel and to make the programming easier the linux kernel provides an easy of creating the linked lists. Using the inbuilt method available in the kernel we can create circular doubly linked lists easily and use them in which ever required in the code.

To be able to use this feature available in the kernel we need to add the header file linux/list.h. The structure that is used for creation of the list"list_head" defined in types.h



To use this structure for creation of a linked list we need to include the structure as a member of the main structure of which we want to create the list. For example to create a linked list called k_list in which we will create a list of numbers we will have to create the structure as



In the above structure "temp" is the real data that we want to store and test_list, which is a structure of the kind "list_head" will be used for the creation of the link list.

Then we will need to create a head for the linked list which will be used start the creation of the list. To create a head we can make use of th macro INIT_LIST_HEAD, which will declared and initialize the list at runtime, or we can use the function LIST_HEAD to initialize the list at compile time.

Once list has been created we can add nodes to the linked list using the function



Let us say we want to add create a linked list of three nodes of the kind k_list structure shown above. let us first create three structures and populate it with data that we want to store in it.



Thus we have created three structures "one","two" and "three" of kind k_list in which we have stored data "10","20", and "30" respectively.

Now to form a linked list of these three structures using lines_add



The first argument to list_add is the pointed to the structure of kind list_head which is a member of k_list and the second argument is a pointer to the head node initialized using INIT_LIST_HEAD.

To traverse through the linked list we can make use of another function available in the kernel



In our example we can use this function as



Where ptr is



Now as we traverse through the list we need to be able to access the data that we have stored in the structure k_list. To be able to ge a pointer to the k_list structures through the pointer to the nodes we can make use of the function



Note: This structure works similar to the function "container_of"

Thus in the example above to get a pointer of kind k_list using the pointer "ptr" we need to use the function as



Where entry is



Putting all the above pieces of code into one module we can test the functions related to the creation of linked list in kernel.

create_list.c



Makefile required to compile the module



To see the output first compile the module using



Insert it into the kernel



To see the output



We can see in the output of dmesg that we have been able to traverse the list using list_for_each successfully.


QR code: GUI tool for encoding decoding QR codes in linux

In the post "QR code: Encode and Decode QR code on linux command line" we saw usage of a command based tool to create QR codes in linux. Let us have a look at a GUI based tool for the same.

QTQR is gui a tool to create QR (Quick Response) code. We will need to install the tool qtqr



Once installed we can launch the tool from GUI in debian under Applications->graphics->QTQR

 photo app_menu.png

We can launch it from terminal using the command qtqr

This will launch a window as shown below.

 photo screen1.png

To create a QR code we can choose what kind of string we want to encode using the pull down menu at the left top as shown below.

 photo data_type.png

Once selected we can enter the text in the text below at the left and then click on "save QR code" at the right bottom and save the QR image.

 photo screen2.png

The QR image for the text "Hello" would look as below.

 photo Hello.png

To decode a QR code using QTQR click on decode at the right corner. While selecting decode we can either choose a file or choose an image being viewed by a webcam. To test the decode, point to the same QR image of "hello" that we created above and click on open.

 photo hello_decoded.png

As we can see the tool has correctly decoded the image.

Useful links
http://code.google.com/p/qtqr/
http://en.wikipedia.org/wiki/QR_code

QR code: Encode and Decode QR code on linux command line

QR(Quick response) code as defined by google is

A machine-readable code consisting of an array of black and white squares, typically used for storing URLs or other information for reading by the camera on a smartphone.

Here is how we can create QR code in linux using command line.

Using command line:

To create QR code using command line we will need to install the package libqrencode3



After successful install of the package we can encode any string of characters, text,url,numbers, into a QR code as shown below.



Let us say we want to encode the string "Hello" into a QR code.



This will creat a hello.png file in the QR format as shown below.

To be able to decode a QR code on the command line we can use the package zbar.



Once the package is installed we can use the command zbarimg to read a QR encoded file



To decode the hello.png QR we created above



Thus we can see that the QR-Code has been correctly recognized as "Hello "

Useful links: http://en.wikipedia.org/wiki/QR_code http://zbar.sourceforge.net/

Answers to Linux Quiz on semaphores

Answers to Quiz on linux Semaphores

1. Race condition occur when
Ans. There is uncontrolled access to shared data

2. The code that is surrounded by a semaphore is termed as
Ans. Critical section

3. To use a semphore as a mutex, semaphore needs to be initalized to the value of
Ans. 1

4.Which of the following will declare and initialize a mutex
Ans. DECLARE_MUTEX

5. The value of the mutex when it is locked by a process is
Ans. 0

6.To create a semaphore which will attempt to get the lock only once, we can use the function

Ans. down_trylock()
7. The functions down and down_interruptible work in similar fashion

Ans. False

8. The function call to release a semaphore is
Ans. up

9. A reader writer semaphore allows
Ans. Multiple readers or only one writer

10. Sending a signal from one thread to other regarding completion of a task/job can be done optimally using
Ans. Completion


Linux Quiz on semaphores

Quiz on linux Semaphores

Quiz on linux Semaphores

  1. Race condition occur when

  2. There is uncontrolled access to data
    There is uncontrolled access to shared data
    Every time kernel accesses user space data
    Every time user communicates with kernel

  3. The code that is surrounded by a semaphore is termed as

  4. Critical section
    Sema section
    Zero section
    Muted section

  5. To use a semphore as a mutex, semaphore needs to be initalized to the value of

  6. 0
    1
    -1
    2

  7. Which of the following will declare and initialize a mutex

  8. DECLARE_MUTEX
    SEMA_INIT_MUTEX
    DECLARE_SEMA
    MUTEX_CREATE

  9. The value of the mutex when it is locked by a process is

  10. 0
    1
    -1
    2

  11. To create a semaphore which will attempt to get the lock only once, we can use the function

  12. down()
    down_tryonce()
    down_trylock()
    down_interrupt()

  13. The functions down and down_interruptible work in similar fashion

  14. True
    False
    Depends on kernel version
    In case of mutex they are same

  15. The function call to release a semaphore is

  16. up
    up_trylock
    up_interruptible
    All of the above

  17. A reader writer semaphore allows

  18. Multiple readers or only one writer
    Multiple writers or only one reader
    Multiple readers and writers
    Only one reader or writer

  19. Sending a signal from one thread to other regarding completion of a task/job can be done optimally

  20. Mutex
    Semaphore
    Completion
    None of the above

Answers : Answers to Linux Quiz on semaphores