//------------------------------------------------------------------- // tasklist.c // // This module creates a pseudo-file (named '/proc/tasklist') // that will display a list of all the system's active tasks. // // NOTE: Written and tested using Linux kernel version 2.6.5. // // programmer: ALLAN CRUSE // written on: 29 DEC 2004 //------------------------------------------------------------------- #include // for init_module() #include // for create_proc_info_entry() static char modname[] = "tasklist"; static int my_get_info( char *buf, char **start, off_t off, int count ) { struct task_struct *task = &init_task; int n_elt = 0, len = 0; do { ++n_elt; len += sprintf( buf+len, "%5d ", task->pid ); len += sprintf( buf+len, "%lu ", task->state ); len += sprintf( buf+len, "%-15s ", task->comm ); if ( ( n_elt % 3 ) == 0 ) len += sprintf( buf+len, "\n" ); task = next_task( task ); } while ( task != &init_task ); 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");