To develop and use kernel modules and character devices. And learn how the Linux OS maintains list of processes and their execution states.
The files hello_world.c has initialization and cleanup functions that are invoked upon loading and unloading the kernel module.
The second file hello_world_n.c is similar, except that it takes command-line arguments with insmod command to print a custom message.
-
Compile the kernel module by running
make
inPart A
directory. -
Run below command to insert/load .ko files to kernel.
sudo insmod hello_world.ko sudo insmod hello_world_n.ko whom=class howmany=10
If the module was successfully inserted, you will see
Banu: Hello World!
message in kernel log. -
Use commands
dmesg
orcat /var/log/kern.log
to see the kernel log messages. -
Run below commands to remove/unload moduels from kernel.
sudo rmmod hello_world sudo rmmod hello_world_n
Upon removing the kernel module, check if kernel log prints the message
Banu: %d: Goodbye, cruel %s!!
- Run
make
inPart B
directory. - Run below command to insert .ko file to kernel.
sudo insmod misc_dd.ko
- Run compile command on file user_space.c
gcc -o user_space user_space.c
- do below,
sudo ./user_space
- You should see
Hello World!
printed.
Part C: Write a kernel module to return list of processes to user space via a character device & Write a user space program to retrieve the list of processes from the kernel module
Implemented a kernel module that creates a /dev/process_list character device. The character device supports the read() operation. When the read() system call is invoked on the character device from a user space process, kernel module will return the following information about all currently running processes:
a. process ID
b. parent process ID
c. the CPU on which the process is running
d. its current state.
Warning: Beware that bugs in kernel code may either crash your kernel immediately or may have no immediate visible effect, but may have a delayed effect. Therefore, you cannot assume that the thing you did most recently is necessarily the cause of a crash.
Also, Implemented a user-space C program that opens character device and outputs the list of processes retrieved from the character device.
- Run
make
inPart C
directory. - Run below command to insert .ko file to kernel.
sudo insmod process_list.ko
- Run compile command on file user.c
gcc -o user user.c
- do below,
sudo ./user
- You should see list of all processes and its state.