Я написал простой модуль ядра, чтобы удалить все гласные из заданной строки. Я хочу узнать о том, сколько памяти выделяется процессом, количество перестановок страниц и количество переключения контекста. Но по какой-то причине sudo pmap pid
ничего не возвращает.
Есть ли какая-либо другая команда, например pmap для процесса уровня ядра?
это код c (t2. c):
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/string.h>
#include <linux/sched.h>
MODULE_LICENSE("GPL");
MODULE_AUTHOR("K Jivitesh Narayan");
MODULE_DESCRIPTION("A program to remove all the vowels from a string");
int init_module(void)
{
char str[20];
int len, i, j;
len=strlen(str);
strcpy(str,"Hello World");
for(i=0; i<len; i++)
{
if(str[i]=='a' || str[i]=='e' || str[i]=='o' || str[i]=='i' || str[i]=='u')
{
for(j=i; j<len; j++)
{
str[j]=str[j+1];
}
len--;
}
}
printk(KERN_INFO "After deleting the vowels, the string will be : %s",str);
printk(KERN_INFO "The process is \"%s\" (pid %i)\n",
current->comm, current->pid);
return 0;
}
void cleanup_module(void){
printk(KERN_INFO "The program is removed \n");
}
Мой Makefile:
obj-m += t2.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
после make
, sudo insmod t2.ko
и dmesg
, я получаю вывод (последние 2 строки):
[ 1108.915141] After deleting the vowels, the string will be : Hll Wrld
[ 1108.915144] The process is "insmod" (pid 3299)
вывод для sudo pmap 3299
- ничто. ошибок нет.
** edit: это код после добавления модуля jiffies
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/string.h>
#include <linux/sched.h>
#include <linux/unistd.h>
#include <linux/jiffies.h>
MODULE_LICENSE("GPL");
MODULE_AUTHOR("K Jivitesh Narayan");
MODULE_DESCRIPTION("A program to remove all the vowels from a string");
int init_module(void)
{
unsigned long j1 = jiffies + 3 * HZ;
char str[20];
int len, i, j;
len=strlen(str);
strcpy(str,"Hello World");
printk(KERN_INFO "The process is \"%s\" (pid %i)\n", current->comm, current->pid);
while(jiffies < j1);
for(i=0; i<len; i++)
{
if(str[i]=='a' || str[i]=='e' || str[i]=='o' || str[i]=='i' || str[i]=='u')
{
for(j=i; j<len; j++)
{
str[j]=str[j+1];
}
len--;
}
}
printk(KERN_INFO "After deleting the vowels, the string will be : %s",str);
return 0;
}
void cleanup_module(void){
printk(KERN_INFO "The program is removed \n");
}