44[ ![ Last Commit] ( https://img.shields.io/github/last-commit/navidpadid/process-info-kernel-module?style=for-the-badge&logo=git&logoColor=white )] ( https://github.com/navidpadid/process-info-kernel-module/commits/main )
55[ ![ License] ( https://img.shields.io/badge/License-Dual%20BSD%2FGPL-blue?style=for-the-badge )] ( LICENSE )
66
7- > A Linux kernel module that extracts detailed process information including memory layout, CPU usage, and ELF sections via ` /proc ` filesystem.
7+ > A Linux kernel module that extracts detailed process and it's thread information including memory layout, CPU usage, and ELF sections via ` /proc ` filesystem.
88
99## Features
1010
1111- ** Process Memory Layout** : Code, Data, BSS, Heap, and Stack addresses
12- - ** CPU Usage Tracking** : Real-time CPU percentage calculation
12+ - ** Visual Memory Map** : Proportional bar chart visualization of memory regions
13+ - ** Thread Information** : List all threads with TID, state, CPU usage, priority, and CPU affinity
14+ - ** CPU Usage Tracking** : Real-time CPU percentage calculation per process and thread
1315- ** ELF Section Analysis** : Binary base address and section boundaries
1416- ** Proc Interface** : Easy access through ` /proc/elf_det/ `
1517- ** Comprehensive Testing** : Unit tests and QEMU-based E2E testing
1618- ** Code Quality** : Pre-configured static analysis (sparse, cppcheck, checkpatch)
1719
20+ ### Example Output
21+
22+ ```
23+ >> Enter process ID (or Ctrl+C to exit): 3115
24+
25+ ================================================================================
26+ PROCESS INFORMATION
27+ ================================================================================
28+ Command line: ./build/test_multithread
29+ Process ID: 3115
30+ Name: test_multithrea
31+ CPU Usage: 2.06%
32+
33+ Memory Layout:
34+ --------------------------------------------------------------------------------
35+ Code Section: 0x0000643f5b8f5000 - 0x0000643f5b8f5459
36+ Data Section: 0x0000643f5b8f7d78 - 0x0000643f5b8f8010
37+ BSS Section: 0x0000643f5b8f8010 - 0x0000643f87d3b000
38+ Heap: 0x0000643f87d3b000 - 0x0000643f87d5c000
39+ Stack: 0x00007ffcdf141220 - 0x00007ffcdf121000
40+ ELF Base: 0x0000643f5b8f4000
41+
42+ Memory Layout Visualization:
43+ --------------------------------------------------------------------------------
44+ Low: 0x0000643f5b8f5000
45+
46+ CODE (1 KB)
47+ [= ]
48+
49+ DATA (664 B)
50+ [= ]
51+
52+ BSS (708 MB)
53+ [================================================= ]
54+
55+ HEAP (132 KB)
56+ [= ]
57+
58+ STACK (128 KB)
59+ [= ]
60+
61+ High: 0x00007ffcdf141220
62+ --------------------------------------------------------------------------------
63+
64+ ================================================================================
65+ THREAD INFORMATION
66+ ================================================================================
67+ TID NAME CPU(%) STATE PRIORITY NICE CPU_AFFINITY
68+ ----- --------------- ------- ----- -------- ---- ----------------
69+ 3115 test_multithrea 2.06 S 0 0 0,1
70+ 3117 test_multithrea 0.32 S 0 0 0,1
71+ 3118 test_multithrea 0.29 S 0 0 0,1
72+ 3119 test_multithrea 0.26 S 0 0 0,1
73+ 3120 test_multithrea 0.14 S 0 0 0,1
74+ --------------------------------------------------------------------------------
75+ ```
76+
1877## Quick Start
1978
2079### Prerequisites
3897 ./build/proc_elf_ctrl
3998 ```
4099
100+ ### Uninstall the Module
101+
102+ ``` bash
103+ sudo make uninstall
104+ ```
105+
41106## Project Structure
42107
43108```
44109kernel_module/
45110├── .devcontainer/ # Dev container config (Docker + VS Code setup)
46111├── .github/ # CI/CD workflows (GitHub Actions)
47112├── docs/ # Detailed documentation
48- ├── scripts / # Testing scripts (QEMU setup, E2E testing automation)
113+ ├── e2e / # End-to-end testing scripts (QEMU setup, automation)
49114├── src/ # Source code (kernel module, user program, tests, helpers)
50115├── build/ # Build artifacts (generated by make)
51116└── Makefile # Build system with quality checks
52117```
53118
54- The program will prompt you to enter a process ID (PID). You can find PIDs using:
119+ ** Notes** :
120+ - ** Memory Visualization** : Each region's bar length is proportional to its actual size
121+ - Sizes are automatically displayed in appropriate units (B, KB, or MB)
122+ - Low/High addresses show the memory address range of the process
123+ - BSS_START and BSS_END may be equal (zero-length BSS) in modern ELF binaries. This is normal.
124+ - Thread STATE: R=Running, S=Sleeping, D=Uninterruptible, T=Stopped, t=Traced, Z=Zombie, X=Dead
125+ - PRIORITY: Shown as nice value (-20 to 19, where lower is higher priority)
126+ - CPU_AFFINITY: Shows which CPUs the thread can run on
55127
56- ``` bash
57- ps aux | grep < process_name>
58- ```
59128
60- ### 3. Example Output
61-
62- ```
63- ************enter the process id: 1234
64-
65- the process info is here:
66- PID NAME CPU(%) START_CODE END_CODE START_DATA END_DATA BSS_START BSS_END HEAP_START HEAP_END STACK_START STACK_END ELF_BASE
67- 01234 bash 0.50 0x0000563a1234 0x0000563a5678 0x0000563a9abc 0x0000563adef0 0x0000563adef0 0x0000563adef0 0x0000563b0000 0x0000563b8000 0x00007ffd12345000 0x00007ffd12340000 0x0000563a1000
68- ```
69-
70- ** Note** : BSS_START and BSS_END may be equal (zero-length BSS) in modern ELF binaries. This is normal.
71-
72- ### 4. Uninstall the Module
73-
74- ``` bash
75- sudo make uninstall
76- ```
77129
78130## Safe Testing with QEMU
79131
@@ -83,28 +135,36 @@ For maximum safety, test the kernel module in an isolated QEMU virtual machine t
83135
84136``` bash
85137# One-time setup
86- ./scripts /qemu-setup.sh
138+ ./e2e /qemu-setup.sh
87139
88140# Start VM
89- ./scripts /qemu-run.sh
141+ ./e2e /qemu-run.sh
90142
91143# In another terminal, run automated tests
92- ./scripts /qemu-test.sh
144+ ./e2e /qemu-test.sh
93145```
94146
95147
96148## Makefile Targets
97149
98150``` bash
99- make all # Build kernel module and user program
100- make install # Install kernel module (requires root)
101- make uninstall # Remove kernel module
102- make unit # Run unit tests (no kernel required)
103- make test # Install module and run user program
104-
105- make format # Format all source files
106- make check # Run all static analysis
107- make clean # Remove build artifacts
151+ make all # Build kernel module and user program
152+ make module # Build kernel module only
153+ make user # Build user program only
154+ make test-multithread # Build multi-threaded test program
155+ make install # Install kernel module (requires root)
156+ make uninstall # Remove kernel module
157+ make unit # Run unit tests (no kernel required)
158+ make test # Install module and run user program
159+
160+ make format # Format all source files
161+ make format-check # Check formatting (CI-friendly)
162+ make check # Run all static analysis
163+ make checkpatch # Check kernel coding style
164+ make sparse # Run sparse static analyzer
165+ make cppcheck # Run cppcheck static analyzer
166+ make clean # Remove build artifacts
167+ make help # Show help message
108168```
109169
110170## Testing
@@ -117,9 +177,9 @@ Runs pure function tests without kernel dependencies.
117177
118178### QEMU Testing (Safe Kernel Testing)
119179``` bash
120- ./scripts /qemu-setup.sh # One-time setup
121- ./scripts /qemu-run.sh # Start VM
122- ./scripts /qemu-test.sh # Run automated tests
180+ ./e2e /qemu-setup.sh # One-time setup
181+ ./e2e /qemu-run.sh # Start VM
182+ ./e2e /qemu-test.sh # Run automated tests
123183```
124184
125185See [ docs/TESTING.md] ( docs/TESTING.md ) for detailed testing documentation.
0 commit comments