GithubHelp home page GithubHelp logo

banu-prasanth-pulicharla / kernel-modules Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 1.0 17 KB

To develop and use kernel modules and character devices. And learn how the Linux OS maintains list of processes and their execution states.

License: MIT License

Makefile 21.46% C 78.54%
c linux kernel kernel-module character-device processes

kernel-modules's Introduction

Kernel Modules to list all processes and their states

Objective

To develop and use kernel modules and character devices. And learn how the Linux OS maintains list of processes and their execution states.

Part A: Learn how to write and execute a Linux kernel module.

Usage and How To Run?

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.

  1. Compile the kernel module by running make in Part A directory.

  2. 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.

  3. Use commands dmesg or cat /var/log/kern.log to see the kernel log messages.

  4. 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!!

Part B: Learn how to write a miscellaneous character device driver

Usage and How To Run?

  1. Run make in Part B directory.
  2. Run below command to insert .ko file to kernel.
    sudo insmod misc_dd.ko
  3. Run compile command on file user_space.c
    gcc -o user_space user_space.c
  4. do below,
    sudo ./user_space
  5. 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

Usage and How To Run?

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.

  1. Run make in Part C directory.
  2. Run below command to insert .ko file to kernel.
    sudo insmod process_list.ko
  3. Run compile command on file user.c
    gcc -o user user.c
  4. do below,
    sudo ./user
  5. You should see list of all processes and its state.

kernel-modules's People

Contributors

banu-prasanth-pulicharla avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

0502506897

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.