C Implementation of Red Black Tree

Include these header files: #include #include #include [terminal] struct rbtNode { int key; char color; struct rbtNode * left, * right, * parent; }; struct rbtNode * root = NULL; void leftRotate(struct rbtNode * x) { struct rbtNode * y; y = x – > right; x – > right = y – > left; …

Read more

C Implementation of K-dimensional Tree

[terminal] #include struct node { int data1, data2, level; struct node * right, * left; }* root, * temp; void inorder(struct node * p) { if (p != NULL) { inorder(p – > left); printf(“\t%d:%d “, p – > data1, p – > data2); inorder(p – > right); } } void postorder(struct node * p) …

Read more

C Implementation of LEFTIST Tree

C Implementation of LEFTIST Tree [terminal] #include struct node { int data, dist; struct node * right, * left; }* root, * temp, * r1, * r2; void inorder(struct node * p) { if (p != NULL) { inorder(p – > left); printf(“\t%d”, p – > data); inorder(p – > right); } } void postorder(struct …

Read more

KVM guest reports errors – How to troubleshoot or track it ? systemtap ?

I have seen reports saying that – under some scenarios, the KVM guest system reports I/O errors in its ‘dmesg’ against virtio block devices and also, some times it cause the filesystems inside the guest to go ‘READONLY’ mode. Tracking such issues are a bit difficult and its a pain. I believe we should make …

Read more

Generate intermediate files ( assembling, preprocessing) in gcc

Let’s start with some GCC commands as shown below. [terminal] [root@humbles-lap gcc]# gcc -S -c program.c [root@humbles-lap gcc]# ls program.c program.s [root@humbles-lap gcc]# file program.s program.s: ASCII assembler program text [root@humbles-lap gcc]# cat program.s |head -n 5 .file “program.c” .section .rodata .align 8 .LC0: .string “\n I am always an example program” [/terminal] How-ever it …

Read more

Kernel module to print process pid, stack..etc information..

When browsing through my filesystem,  I saw a kernel module which I wrote a way back to print information about the current process and its stack, pid..etc.. Also, this module prints all the processes running in the system. So I loaded that into my running system and it was obedient 🙂

I had called him ‘process_informer.ko’..

[root@humbles-lap hello]# make
make -C /lib/modules/2.6.30.10-105.2.23.fc11.x86_64/build M=/misc/my_kernel_modules/hello modules
make[1]: Entering directory `/usr/src/kernels/2.6.30.10-105.2.23.fc11.x86_64′
CC [M]  /misc/my_kernel_modules/hello/process_informer.o
Building modules, stage 2.
MODPOST 1 modules
CC      /misc/my_kernel_modules/hello/process_informer.mod.o
LD [M]  /misc/my_kernel_modules/hello/process_informer.ko
make[1]: Leaving directory `/usr/src/kernels/2.6.30.10-105.2.23.fc11.x86_64′
[root@humbles-lap hello]#

[root@humbles-lap hello]# lsmod |grep process
[root@humbles-lap hello]# insmod process_informer.ko
[root@humbles-lap hello]# lsmod |grep process
process_informer       12427  0
[root@humbles-lap hello]#

[root@humbles-lap hello]# modinfo process_informer.ko
filename:       process_informer.ko
license:        GPL
description:    Module, for fun
version:        1.0.0
author:         Humble Chirammal
srcversion:     C62BE5C41BEC6E733271884
depends:        
vermagic:       2.6.30.10-105.2.23.fc11.x86_64 SMP mod_unload
[root@humbles-lap hello]#

[root@humbles-lap hello]# rmmod process_informer.ko
[root@humbles-lap hello]# lsmod |grep process

Jun  1 00:01:17 humbles-lap kernel: [ 6225.683529]  Hi World, somebody loaded me  ==> __init()
Jun  1 00:01:17 humbles-lap kernel: [ 6225.683533]
Jun  1 00:01:17 humbles-lap kernel: [ 6225.683534]  I am informed to track current process
Jun  1 00:01:17 humbles-lap kernel: [ 6225.683538]
Jun  1 00:01:17 humbles-lap kernel: [ 6225.683539]       Current process is : ‘insmod’
Jun  1 00:01:17 humbles-lap kernel: [ 6225.683540]        pid : ‘8875’
Jun  1 00:01:17 humbles-lap kernel: [ 6225.683541]       Kernel release : ‘2.6.30.10-105.2.23.fc11.x86_64’
Jun  1 00:01:17 humbles-lap kernel: [ 6225.683544]      ‘RUNNABLE’ OR ‘UNRUNNABLE’
Jun  1 00:01:17 humbles-lap kernel: [ 6225.683547]       PRIO : 120  STATE: 0
Jun  1 00:01:17 humbles-lap kernel: [ 6225.683550]
Jun  1 00:01:17 humbles-lap kernel: [ 6225.683551]       My thread_info located at : ffff88009d0dc000
Jun  1 00:01:17 humbles-lap kernel: [ 6225.683552]
Jun  1 00:01:17 humbles-lap kernel: [ 6225.683555]      Process 0 is  : swapper/0     pid :: 0
Jun  1 00:01:17 humbles-lap kernel: [ 6225.683558]      Process 1 is  : systemd     pid :: 1
Jun  1 00:01:17 humbles-lap kernel: [ 6225.683561]      Process 2 is  : kthreadd     pid :: 2
Jun  1 00:01:17 humbles-lap kernel: [ 6225.683565]      Process 3 is  : ksoftirqd/0     pid :: 3
Jun  1 00:01:17 humbles-lap kernel: [ 6225.683568]      Process 4 is  : migration/0     pid :: 6
Jun  1 00:01:17 humbles-lap kernel: [ 6225.683571]      Process 5 is  : watchdog/0     pid :: 7

************Truncated..

Jun  1 00:01:17 humbles-lap kernel: [ 6225.684065]      Process 157 is  : su     pid :: 7296
Jun  1 00:01:17 humbles-lap kernel: [ 6225.684068]      Process 158 is  : bash     pid :: 7306
Jun  1 00:01:17 humbles-lap kernel: [ 6225.684071]      Process 159 is  : bash     pid :: 7398
Jun  1 00:01:17 humbles-lap kernel: [ 6225.684074]      Process 160 is  : su     pid :: 7419

Jun  1 00:02:08 humbles-lap kernel: [ 6225.684117]      Process 174 is  : sleep     pid :: 8856

Jun  1 00:02:08 humbles-lap kernel: [ 6276.449168]   Bye Guys, he is kind enough to unload me      ==> __exit()

Hmmmm.. there are ‘174’ processes in my system …