University of Colorado at Colorado Springs CS4500/ Fall 2018 Operating Systems Project 1 - System Calls and Processes

Similar documents
Part A: Setup your kernel development environment

Project 1: Syscalls for synchronization 1

Creating a system call in Linux. Tushar B. Kute,

PRINCIPLES OF OPERATING SYSTEMS

Hint #1. Define a syscall

EE516: Embedded Software Project 1. Setting Up Environment for Projects

Lab 1 Introduction to UNIX and C

Project 2 Linux Kernel Hacking

Project 1 System Calls

QEMU and the Linux Kernel

CSC111 Computer Science II

Oregon State University School of Electrical Engineering and Computer Science. CS 261 Recitation 1. Spring 2011

System Calls (Φροντιστήριο για την 3η σειρά) Dimitris Deyannis

Saint Louis University. Intro to Linux and C. CSCI 2400/ ECE 3217: Computer Architecture. Instructors: David Ferry

CS 0449 Project 4: /dev/rps Due: Friday, December 8, 2017, at 11:59pm

ECEN 449: Microprocessor System Design Department of Electrical and Computer Engineering Texas A&M University

Problem Set 1: Unix Commands 1

CSE 351. Introduction & Course Tools

Exercise 1: Basic Tools

Project 2: Shell with History1

Unix/Linux Basics. Cpt S 223, Fall 2007 Copyright: Washington State University

Your first C and C++ programs

There are three separate utilities for configuring Linux kernel and they are listed below: Command-line interface # make config. Figure 1.

Project No. 2: Process Scheduling in Linux Submission due: April 12, 2013, 11:59pm

Laboratory 1 Semester 1 11/12

CS Fundamentals of Programming II Fall Very Basic UNIX

CS155: Computer Security Spring Project #1

BIL 104E Introduction to Scientific and Engineering Computing. Lecture 14

Installing Virtualbox Guest Additions Vboxadditions on CentOS 7, Fedora 19 / 20 and RHEL 6.5 / 5.10 on Windows host

CS240: Programming in C

Operating Systems (234123) Spring 2017 (Homework Wet 1) Homework 1 Wet

CS 253: Intro to Systems Programming 1/21

Formatting 1. Commands starting with $ are Linux console commands on the host PC:

Lab 1 Introduction to UNIX and C

Beyond this course. Machine code. Readings: CP:AMA 2.1, 15.4

Computer Science 322 Operating Systems Mount Holyoke College Spring Topic Notes: C and Unix Overview

CS 215 Fundamentals of Programming II Spring 2019 Very Basic UNIX

143a, Spring 2018 Discussion Week 4 Programming Assignment. Jia Chen 27 Apr 2018

Project 0: Linux & Virtual Machine Dabbling

CS Programming Languages Fall Homework #2

CS 1550 Project 3: File Systems Directories Due: Sunday, July 22, 2012, 11:59pm Completed Due: Sunday, July 29, 2012, 11:59pm

Assignment 1: Build Environment

Working with Basic Linux. Daniel Balagué

CSC374, Spring 2010 Lab Assignment 1: Writing Your Own Unix Shell

York University Faculty Science and Engineering Fall 2008

Short Read Sequencing Analysis Workshop

SDK. About the Cisco SDK. Installing the SDK. Procedure. This chapter contains the following sections:

Final Project: LC-3 Simulator

In either case, remember to delete each array that you allocate.

Please choose the best answer. More than one answer might be true, but choose the one that is best.

82V391x / 8V893xx WAN PLL Device Families Device Driver User s Guide

Operating Systems 16 - CS 323 Assignment #2

/dev/hello_world: A Simple Introduction to Device Drivers under Linux

Dirty COW Attack Lab

CS342 - Spring 2019 Project #3 Synchronization and Deadlocks

CS 300 Leftovers. CS460 Pacific University 1

Hello, World! in C. Johann Myrkraverk Oskarsson October 23, The Quintessential Example Program 1. I Printing Text 2. II The Main Function 3

Linux Kernel Update - from scratch (almost) Platform: Archlinux, UEFI, GRUB2, and initramfs. Prof. Rossano Pablo Pinto

EEE3052: Introduction to Operating Systems. Fall Project #1

Hand-on Labs for Chapter 1 and Appendix A CSCE 212 Introduction to Computer Architecture, Spring

Programming the DMCC in C

Linux Essentials Objectives Topics:

COMP s1 Lecture 1

UNIVERSITY OF NEBRASKA AT OMAHA Computer Science 4500/8506 Operating Systems Fall Programming Assignment 1 (updated 9/16/2017)

CS 361S - Network Security and Privacy Spring Project #2

CMPT 300. Operating Systems. Brief Intro to UNIX and C

Instructions PLEASE READ (notice bold and underlined phrases)

CS 470 Operating Systems Spring 2013 Shell Project

Programs. Function main. C Refresher. CSCI 4061 Introduction to Operating Systems

CS155: Computer Security Spring Project #1. Due: Part 1: Thursday, April pm, Part 2: Monday, April pm.

CS11002 Programming and Data Structures Spring Introduction

TEMU installation and user manual

Operating System. Hanyang University. Hyunmin Yoon Operating System Hanyang University

Introduction to Supercomputing

Linux Kernel Module Programming. Tushar B. Kute,

It is academic misconduct to share your work with others in any form including posting it on publicly accessible web sites, such as GitHub.

CS 4410, Fall 2017 Project 1: My First Shell Assigned: August 27, 2017 Due: Monday, September 11:59PM

POSTouch Open Source Driver (OSE) Installation Guide

Instructions for setting up to compile and run OSGPS code under Linux

COUCHDB - INSTALLATION

Programming Assignment #4

Project 2 - Kernel Memory Allocation

CS 213, Fall 2002 Lab Assignment L5: Writing Your Own Unix Shell Assigned: Oct. 24, Due: Thu., Oct. 31, 11:59PM

CS 220: Introduction to Parallel Computing. Beginning C. Lecture 2

Introduction to C. Zhiyuan Teo. Cornell CS 4411, August 26, Geared toward programmers

Communications Library Manual

CS 143A. Principles of Operating Systems. Instructor : Prof. Anton Burtsev

EECS Software Tools. Lab 2 Tutorial: Introduction to UNIX/Linux. Tilemachos Pechlivanoglou

QEMU Basic. Create the Hardware System

Intermediate Programming, Spring Misha Kazhdan

Outline. Lecture 1 C primer What we will cover. If-statements and blocks in Python and C. Operators in Python and C

CS 361S - Network Security and Privacy Spring Project #2

CS197U: A Hands on Introduction to Unix

Operating Systems and Networks Assignment 9

CSE 391 Lecture 1. introduction to Linux/Unix environment

CS 211 Programming I for Engineers

Lab 1: Introduction to C, ASCII ART & the Linux Command Line

CS 161 Computer Security

1. Static Linking. CS3214 Spring 2012 Exercise 5

Computer Science 2500 Computer Organization Rensselaer Polytechnic Institute Spring Topic Notes: C and Unix Overview

Transcription:

University of Colorado at Colorado Springs CS4500/5500 - Fall 2018 Operating Systems Project 1 - System Calls and Processes Instructor: Yanyan Zhuang Total Points: 100 Out: 8/29/2018 Due: 11:59 pm, Friday, 9/21/2018 Introduction The purpose of this project is to study how system calls and processes are managed by the Linux OS. The objectives of this project is to: 1. Get familiar with the Linux environment. 2. Learn how to build a Linux kernel. 3. Learn how to add a new system call in the Linux kernel. 4. Learn how to obtain various information for a running process from the Linux kernel. Project submission For each project, please create a zipped file containing the following items, and submit it to Canvas. 1. A report that includes (1) the (printed) full names of the project members, and the statement: We have neither given nor received unauthorized assistance on this work; (2) the name of your virtual machine (VM), and the password for the instructor account (details see Accessing VM below); and (3) a brief description about how you solved the problems and what you learned. For example, you may want to make a typescript of the steps in building the Linux kernel, or the changes you made in the Linux kernel source for adding a new system call. The report can be in txt, doc, or pdf format. 2. The source code including both the kernel-level code you added and the user-level testing program. 1 1 In case there are issues accessing your VM, submitting your source code separately would allow the instructor to give partial grade. 1

Accessing VM. Each team should specify the name of your VM that the instructor can login to check the project results. Please create a new user account called instructor in your VM, and place your code in the home directory of the instructor account (i.e., /home/instructor). Make sure the instructor has the appropriate access permission to your code. In your project report, include your password for the instructor account. Tasks Task 0: Building the Linux kernel (20 points) Step 1: Getting the Linux kernel code Before you download and compile the Linux kernel source, make sure that you have development tools installed on your system. In CentOS, install these software using yum (Note that the # prompt indicates that the command requires root privilege. $ indicates normal user privilege): # yum install -y gcc ncurses-devel make wget Visit http://kernel.org and download the source code of your current running kernel. To obtain the version of your current kernel, type: $ uname -r $ 2.6.32-220.el6.i686 Then, download kernel 2.6.32 and extract the source: $ wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.32.tar.gz $ tar xvzf linux-2.6.32.tar.gz If you are using kernel 2.6.39.4, do the following: $ wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.39.4.tar.gz $ tar xvzf linux-2.6.39.4.tar.gz We will refer LINUX SOURCE to the top directory of the kernel source, i.e., linux-2.6.32/. Step 2: Configure your new kernel It s a good idea to take a snapshot of your VM in case things get messed up. Before compiling the new kernel, a.config file needs to be generated in the top directory of the kernel source. To generate the config file, type this in LINUX SOURCE: $ make localmodconfig Make sure that you type enter when prompted for questions. If you are using kernel 2.6.39.4, $ make localmodconfig lists a lot of questions. If you are not sure how to choose, use $ make allyesconfig Note $ make allyesconfig will make the first time (only the first time) when you run the next step very long (about an hour). So sit back and have some tea. Step 3: Compile the kernel In LINUX SOURCE, compile to create a compressed kernel image: $ make -j8 Replace 8 in make -j8 with the number of cores you have for the VM (typically a number between 4-8. if you don t know, this wouldn t affect you much, just an optimization option). 2

Step 4: Install the kernel To compile and install kernel modules (to become the root user, use the su command): $ su - # make modules # make modules install Install the kernel: # export KERNELVERSION=$(make kernelversion) # cp arch/x86/boot/bzimage /boot/vmlinuz-$kernelversion # cp System.map /boot/system.map-$kernelversion When you run the two cp commands above, and are asked whether to overwrite the existing files, make sure that you type y to overwirte. # new-kernel-pkg --mkinitrd --install $KERNELVERSION The kernel image and other related files have been installed into the /boot directory. Step 5: Reboot your VM Reboot to the new kernel: # reboot Please make sure that you select the new kernel that has been built. 2 After boot, check if you have the new kernel: $ uname -r $ 2.6.32 (or $ 2.6.39.4) Task 1: Add a new system call to the Linux kernel (20 points) In this task, we will add a simple system call helloworld to the Linux kernel. The system call prints out a Hello World! message to the syslog. You need to implement the system call in the kernel and write a user-level program to test your new system call. Step 1: Implement your system call Change your current working directory to the kernel source directory. $ cd LINUX SOURCE Make a new directory called my source to contain your implementation: $ mkdir my source Create a C file and implement your system call here: $ touch my source/sys helloworld.c Edit the source code to include the following implementation (be careful about the quotation marks type the printk function by hand rather than copy&paste to avoid encoding issues): $ vim my source/sys helloworld.c #include <linux/kernel.h> #include <linux/sched.h> asmlinkage int sys helloworld (void) 2 In the past, some people had the issue of not having an option to select a new build upon reboot. If this happens, try holding down the shift key while reboot. When you see a message Boot CentOS (2.6.32-220.el6.i686) hit enter right away. 3

{ printk(kern EMERG Hello World!\n ); return 0; } Add a Makefile to the my source folder: $ touch my source/makefile $ vim my source/makefile # #Makefile of the new system call # obj-y := sys helloworld.o Modify the Makefile in the top directory to include the new system call in the kernel compilation: $ vim Makefile Find the line where core-y is defined and add the my source directory to it: core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ my source/ Add a function pointer to the new system call in arch/x86/kernel/syscall table 32.S: $ vim arch/x86/kernel/syscall table 32.S Add the following line to the end of this file:.long sys helloworld /* 337 */ Now you have defined helloworld as system call 337. In kernel 2.6.39.4:.long sys helloworld /* 345 */ Register your system call with the kernel by editing arch/x86/include/asm/unistd 32.h. If the last system call in arch/x86/kernel/syscall table 32.S has an id number 336, then our new system call should be numbered as 337. Add this to the file unistd 32.h, right below the definition of system call 336: #define NR helloworld 337 Modify the total number of system calls to 337 + 1 = 338: #define NR syscalls 338 In kernel 2.6.39.4: #define NR helloworld 345 #define NR syscalls 346 Declare the system call routine. Add the following to the end of arch/x86/include/asm/syscall.h (right before the line CONFIG X86 32, near the end of the file): asmlinkage int sys helloworld(void); Repeat steps 3, 4 and 5 in task 0 to re-comple, install and reboot to the new kernel. 4

Step 2: Write a user-level program to test your system call Go to your home directory and create a test program test syscall.c: #include <linux/unistd.h> #include <sys/syscall.h> #include <sys/types.h> #include <stdio.h> #define NR helloworld 337 (345 in kernel 2.6.39.4) int main(int argc, char *argv[]) { syscall( NR helloworld); return 0; } Compile the program: $ gcc test syscall.c -o test syscall Test the new system call by running: $./test syscall If your program hangs, hit enter to continue. The test program will call the new system call and output a helloworld message at the tail of the output of dmesg (try dmesg tail). Task 2: Extend your new system call to print out the calling process s information (35 points) Follow the instructions we discussed above and implement another system call print self. This system call identifies the current process at the user-level and print out various information of the process. Implement the print self system call and print out the following information of the current process: Process id, running state, and program name The same above information of its parent processes until init HINT: The macro current returns a pointer to the task struct of the current running process. See the following link: http://linuxgazette.net/133/saha.html Please pay attention to the last example that traces from the current process back to init. Task 3: Extend your new system call to print out the information of an arbitrary process identified by its PID (25 points) Implement another system call print other to print the information for an arbitrary process. The system call takes a process pid as its argument and outputs the above information (same as Task 2) of this process. HINT: You can start from the init process and iterate over all the processes. For each process, compare its pid with the target pid. If there is a match, return the pointer to this task struct. A better approach would be to to use the functions that Linux provides to look up the process in the process table. You may refer to the lecture slides. To get a valid PID for a process that s active, you may use command pgrep bash. bash is the default command line shell. pgrep bash will provide PIDs of bash. You can choose 5

any of them if you get more than one. More information about command line tools to get process information: http://linuxcommando.blogspot.com/2007/11/how-to-look-up-process.html 6