//------------------------------------------------------------------- // memused.c // // This module creates a pseudo-file named '/proc/memused' that // lets an application see its allocation of virtual memory (in // killobytes), as recorded in its task_struct's 'mm->total_vm' // field (where the number of the task's 4KB pages is stored). // // NOTE: Developed and tested with Linux kernel version 2.4.26. // // programmer: ALLAN CRUSE // written on: 15 NOV 2004 //------------------------------------------------------------------- #include // for init_module() #include // for create_proc_info_entry() static char modname[] = "memused"; static int my_get_info( char *buf, char **start, off_t off, int count ) { struct task_struct *task = current; int kbytes = 4 * task->mm->total_vm; int len = 0; len += sprintf( buf+len, "%15s ", task->comm ); len += sprintf( buf+len, "%d kB ", kbytes ); len += sprintf( buf+len, "\n" ); return len; } int init_module( void ) { printk( "<1>\nInstalling \'%s\' module\n", modname ); create_proc_info_entry( modname, 0, NULL, my_get_info ); return 0; //SUCCESS } void cleanup_module( void ) { remove_proc_entry( modname, NULL ); printk( "<1>Removing \'%s\' module\n", modname ); } MODULE_LICENSE("GPL");