Search

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