* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Download project2 - 408 Coding School
Plan 9 from Bell Labs wikipedia , lookup
Spring (operating system) wikipedia , lookup
Process management (computing) wikipedia , lookup
Mandriva Linux wikipedia , lookup
Linux kernel wikipedia , lookup
Burroughs MCP wikipedia , lookup
Linux adoption wikipedia , lookup
CS4560 Operating Systems Programming Project #2 Due date: April 14 (Friday), 2017 The file name of your reports have to be formatted as CS4560_Project_n_xxxxxxx.docx (or .pdf) where n is the project id and xxxxxxx is your student id ). 1 Spring 2017 Operating Systems Project Description Refer to the textbook for Chapter 3 Programming Project: Linux Kernel Module for Listing Tasks on page 159 of the 9th edition. In this project, you will write a kernel module that lists all current tasks in a Linux system. Be sure to review the programming project in Chapter 2, which deals with creating Linux kernel modules, before you begin this project. The project can be completed using the Linux virtual machine provided with this text. The instructions are posted at the textbook companion web site http://www.os-book.com/.) Part I –Iterating over Tasks Linearly Design a kernel module that iterates through all tasks in the system using the for each process() macro. In particular, output the task name (known as executable name), state, and process id of each task. Follow the instructions on the textbook and do the following. Compile and run the program given below. Take screen shots of the output of your program (saved in the kernel log Find and run the Linux command to list all the processes. Please discuss how different or similar the outputs of your program and the Linux command. #include <linux/init.h> #include <linux/module.h> #include <linux/kernel.h> #include <linux/sched.h> char* msg[] = {"RUNNING","INTERRUPTIBLE","UNINTERRUPTIBLE", "ZOMBIE", "STOPPED"}; /* performs a depth-first traversal of the list of tasks in the system. */ void traverse(struct task_struct *ptr) { struct list_head *list; struct task_struct *next_task; if (thread_group_leader(ptr)) printk(KERN_INFO ">>>name = %s, id=%d, state=%s<<<\n", ptr->comm, ptr->pid, msg[ptr->state]); Spring 2017 2 list_for_each(list, &ptr->children) { next_task = list_entry(list, struct task_struct, sibling); traverse(next_task); } } int simple_init(void) { bool partI = true ; // change it to false for partII printk(KERN_INFO "Loading Module\n"); if ( partI ) { struct task_struct *ptr; for_each_process(ptr) { printk(KERN_INFO ">>>name = %s, id=%d, state=%s<<<\n", ptr->comm, ptr->pid, msg[ptr->state]); } } else { traverse(&init_task); } return 0; } void simple_exit(void) { printk(KERN_INFO "Removing Module\n"); } module_init( simple_init ); module_exit( simple_exit ); MODULE_LICENSE("GPL"); MODULE_DESCRIPTION("Process Module"); MODULE_AUTHOR("SGG"); Part II –Iterating over Tasks with a Depth-First Search Tree The second portion of this project involves iterating over all tasks in the system using a depthfirst search (DFS) tree. Read and understand the purpose of this part of the project. Make the following change to the program given in part I. Change “bool partI = true ;” to “bool partI = false;” Compile and install this module. Take the screen shots of the output of your program (saved in the kernel log) Spring 2017 3 Find the Linux command to display the process tree. Please discuss how different or similar the outputs of your program and Linux command. Provide a demonstration to convince me that that the program have indeed performed an appropriate DFS iteration. Spring 2017 4